/* هوش مصنوعی رایگان (ai.php) */
.ai-app {
	display: flex;
	height: calc(100vh - 140px);
	min-height: 480px;
	margin: 16px 0;
	background: #fff;
	border: 1px solid #e9ecef;
	border-radius: 16px;
	box-shadow: 0 4px 12px rgba(0, 0, 0, .06);
	overflow: hidden;
	position: relative;
}

/* Sidebar: recent conversations (right side in RTL) */
.ai-sidebar {
	width: 270px;
	flex-shrink: 0;
	border-left: 1px solid #e9ecef;
	background: #f8f9fa;
	display: flex;
	flex-direction: column;
	padding: 12px;
}
.ai-new { border-radius: 10px; }
.ai-list-title { font-size: 12px; color: #6c757d; margin: 16px 6px 6px; }
.ai-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.ai-list li {
	display: flex;
	align-items: center;
	border-radius: 8px;
	cursor: pointer;
	padding: 8px 10px;
	margin-bottom: 2px;
	font-size: 14px;
}
.ai-list li:hover { background: #e9ecef; }
.ai-list li.active { background: #dbe7ff; }
.ai-list .ai-item-title { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ai-list .ai-item-delete {
	border: 0;
	background: none;
	color: #adb5bd;
	padding: 0 4px;
	visibility: hidden;
}
.ai-list li:hover .ai-item-delete, .ai-list li.active .ai-item-delete { visibility: visible; }
.ai-list .ai-item-delete:hover { color: #dc3545; }

/* Main column */
.ai-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.ai-header { display: flex; align-items: center; padding: 10px 16px; border-bottom: 1px solid #e9ecef; }
.ai-title { font-size: 16px; margin: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ai-toggle { display: none; color: #495057; padding: 0 8px 0 4px; }

.ai-messages { flex: 1; overflow-y: auto; padding: 20px 16px; scroll-behavior: smooth; }
.ai-msg { max-width: 760px; margin: 0 auto 16px; display: flex; }
.ai-msg.user { justify-content: flex-end; }  /* the user's own messages on the end side (left in Persian), as in the app */
.ai-msg.assistant { justify-content: flex-start; }
.ai-bubble {
	border-radius: 16px;
	padding: 10px 14px;
	line-height: 1.9;
	word-wrap: break-word;
	overflow-wrap: anywhere;
	max-width: 100%;
	text-align: start; /* the site's stylesheet forces left; follow the message's own direction */
}
.ai-msg.user .ai-bubble { background: #0d6efd; color: #fff; white-space: pre-wrap; max-width: 85%; }
.ai-msg.assistant .ai-bubble { background: #f1f3f5; color: #212529; width: 100%; }
.ai-msg.error .ai-bubble { background: #fef2f2; color: #b02a37; border: 1px solid #fecaca; }

/* Markdown in answers */
.ai-bubble p { margin: 0 0 .6em; }
.ai-bubble p:last-child { margin-bottom: 0; }
.ai-bubble ul, .ai-bubble ol { padding-inline-start: 1.4em; padding-inline-end: 0; margin-bottom: .6em; }
.ai-bubble h1, .ai-bubble h2, .ai-bubble h3, .ai-bubble h4 { font-size: 1.05em; font-weight: bold; margin: .8em 0 .4em; }
.ai-bubble pre {
	direction: ltr;
	text-align: left;
	background: #212529;
	color: #f8f9fa;
	border-radius: 8px;
	padding: 10px 12px;
	overflow-x: auto;
	font-size: 13px;
}
.ai-bubble code { direction: ltr; unicode-bidi: embed; background: rgba(0, 0, 0, .06); border-radius: 4px; padding: 0 4px; }
.ai-bubble pre code { background: none; padding: 0; color: inherit; }
.ai-bubble table { border-collapse: collapse; margin: .6em 0; display: block; overflow-x: auto; }
.ai-bubble th, .ai-bubble td { border: 1px solid #dee2e6; padding: 4px 8px; }
.ai-bubble blockquote { border-inline-start: 3px solid #ced4da; padding-inline-start: 10px; color: #495057; margin: .6em 0; }

.ai-meta { font-size: 12px; color: #868e96; margin-top: 6px; display: flex; gap: 12px; align-items: center; }
.ai-meta button { border: 0; background: none; color: #868e96; padding: 0; cursor: pointer; }
.ai-meta button:hover { color: #0d6efd; }

.ai-typing span {
	display: inline-block; width: 7px; height: 7px; margin: 0 2px; border-radius: 50%;
	background: #adb5bd; animation: ai-blink 1.2s infinite both;
}
.ai-typing span:nth-child(2) { animation-delay: .2s; }
.ai-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes ai-blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

/* Empty state */
.ai-empty { text-align: center; margin-top: 8vh; color: #495057; }
.ai-empty-icon, .ai-login-icon { font-size: 40px; color: #0d6efd; margin-bottom: 8px; }
.ai-suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 620px; margin: 16px auto 0; }
.ai-chip {
	border: 1px solid #dee2e6; background: #fff; border-radius: 18px; padding: 6px 14px;
	font-size: 14px; color: #495057; cursor: pointer;
}
.ai-chip:hover { border-color: #0d6efd; color: #0d6efd; }

/* Composer */
.ai-composer {
	display: flex; align-items: flex-end; gap: 8px;
	max-width: 792px; width: 100%; margin: 0 auto; padding: 8px 16px 4px;
}
.ai-composer textarea {
	text-align: start;
	flex: 1; resize: none; border: 1px solid #ced4da; border-radius: 14px;
	padding: 10px 14px; max-height: 200px; line-height: 1.7; outline: none;
}
.ai-composer textarea:focus { border-color: #86b7fe; box-shadow: 0 0 0 3px rgba(13, 110, 253, .15); }
.ai-send, .ai-attach {
	border-radius: 50%; width: 44px; height: 44px; padding: 0; flex-shrink: 0;
	display: flex; align-items: center; justify-content: center; font-size: 17px; line-height: 1;
}
.ai-send .fa { transform: translate(-1px, 2px); } /* the glyph sits high and its weight leans right */
.ai-attach { background: #f1f3f5; color: #495057; border: 0; }
.ai-attach:hover { background: #e9ecef; color: #0d6efd; }

/* Image picked for the next message */
.ai-attachment { position: relative; max-width: 792px; width: 100%; margin: 0 auto; padding: 8px 16px 0; text-align: start; }
.ai-attachment img { height: 72px; max-width: 160px; object-fit: cover; border-radius: 10px; border: 1px solid #dee2e6; }
.ai-attachment-box { position: relative; display: inline-block; }
.ai-attachment-remove {
	position: absolute; top: -8px; left: -8px; width: 22px; height: 22px; line-height: 20px; padding: 0;
	border-radius: 50%; border: 0; background: #343a40; color: #fff; font-size: 16px; cursor: pointer;
}
.ai-app.dragging .ai-main { outline: 2px dashed #0d6efd; outline-offset: -8px; }

/* Image in a sent message */
.ai-msg-image { display: block; max-width: 260px; max-height: 260px; border-radius: 12px; margin-bottom: 6px; cursor: zoom-in; background: rgba(255,255,255,.3); min-height: 60px; min-width: 60px; }
.ai-note { text-align: center; font-size: 11px; color: #adb5bd; padding: 0 16px 8px; }

.ai-login { max-width: 520px; margin: 48px auto; border-radius: 16px; }
.nav-ai { font-weight: bold; }

/* Phones: the sidebar slides over the chat */
@media (max-width: 767px) {
	.ai-app { height: calc(100vh - 90px); margin: 8px -15px; border-radius: 0; border-left: 0; border-right: 0; }
	.ai-toggle { display: inline-block; }
	.ai-sidebar {
		position: absolute; top: 0; bottom: 0; right: 0; z-index: 10; width: 82%; max-width: 300px;
		transform: translateX(100%); transition: transform .2s ease; box-shadow: -4px 0 16px rgba(0, 0, 0, .12);
	}
	.ai-app.sidebar-open .ai-sidebar { transform: none; }
	.ai-list .ai-item-delete { visibility: visible; } /* no hover on touch screens */
	.ai-messages { padding: 12px 10px; }
	.ai-msg.user .ai-bubble { max-width: 92%; }
}
