/* =========================================================
   مخططات قيد التوضيحية + الصور الداخلية
   يولّدها خط المحتوى داخل المقالات: qd-flow / qd-layers / qd-compare / qd-note / qd-warn
   وكتل Mermaid (pre.qeeid-mermaid) والصور (figure.qeeid-figure).
   مستقل عن غلاف المقال حتى تعرضه لوحة المصنع بالشكل نفسه.
   ========================================================= */

.qd-flow, .qd-layers, .qd-compare, .qeeid-mermaid-out, .qd-note, .qd-warn {
	--qd-bg: #f8fafd;
	--qd-card: #ffffff;
	--qd-line: #e2e8f0;
	--qd-ink: #0f172a;
	--qd-mut: #5b6b80;
	--qd-blue: #2563eb;
	--qd-blue-soft: #eaf1ff;
	--qd-amber: #d4891a;
	--qd-amber-soft: #fff6e6;
	--qd-green: #0f9d74;
}
[data-theme="dark"] :is(.qd-flow, .qd-layers, .qd-compare, .qeeid-mermaid-out, .qd-note, .qd-warn) {
	--qd-bg: #141e2c;
	--qd-card: #1a2638;
	--qd-line: #2a3b54;
	--qd-ink: #e7eef8;
	--qd-mut: #a5b4c9;
	--qd-blue: #6ea8ff;
	--qd-blue-soft: #1c2d4a;
	--qd-amber: #f5b454;
	--qd-amber-soft: #2e2617;
	--qd-green: #43d9a3;
}

/* ---------- الإطار المشترك ---------- */
.qd-flow, .qd-layers, .qd-compare {
	margin: 2.2rem 0;
	padding: 1.3rem 1.3rem 1.4rem;
	background: var(--qd-bg);
	border: 1px solid var(--qd-line);
	border-radius: 16px;
	color: var(--qd-ink);
	direction: rtl;
	text-align: right;
}
.qd-title {
	display: flex;
	align-items: center;
	gap: .55rem;
	margin: 0 0 1.1rem;
	font-size: .92rem;
	font-weight: 700;
	color: var(--qd-mut);
}
.qd-title::before {
	content: '';
	width: 18px;
	height: 4px;
	border-radius: 3px;
	background: linear-gradient(90deg, var(--qd-amber), var(--qd-blue));
	flex: none;
}
.qd-flow ol, .qd-layers ul, .qd-compare ul {
	list-style: none;
	margin: 0;
	padding: 0;
}
.qd-flow li, .qd-layers li, .qd-compare li { margin: 0; }
.qd-flow b, .qd-layers b {
	display: block;
	font-weight: 700;
	color: var(--qd-ink);
	line-height: 1.5;
}
.qd-flow li span, .qd-layers li span {
	display: block;
	margin-top: .2rem;
	font-size: .88rem;
	line-height: 1.7;
	color: var(--qd-mut);
}

/* ---------- خطوات متسلسلة: أفقية حتى 4 خطوات، عمودية لما فوقها وعلى الجوال ---------- */
.qd-flow ol {
	counter-reset: qd;
	display: grid;
	gap: 14px;
	grid-template-columns: 1fr;
}
.qd-flow li {
	counter-increment: qd;
	position: relative;
	padding: .9rem 3.4rem .9rem 1rem;
	background: var(--qd-card);
	border: 1px solid var(--qd-line);
	border-radius: 12px;
}
.qd-flow li::before {
	content: counter(qd);
	position: absolute;
	top: .85rem;
	right: .9rem;
	width: 30px;
	height: 30px;
	border-radius: 50%;
	display: grid;
	place-items: center;
	font-size: .85rem;
	font-weight: 800;
	color: #fff;
	background: var(--qd-blue);
	box-shadow: 0 0 0 4px var(--qd-blue-soft);
}
/* الموصل العمودي بين الخطوات */
.qd-flow li:not(:last-child)::after {
	content: '';
	position: absolute;
	right: calc(.9rem + 14px);
	bottom: -15px;
	width: 2px;
	height: 16px;
	background: var(--qd-line);
}
@media (min-width: 720px) {
	.qd-flow ol:not(:has(> li:nth-child(5))) {
		grid-auto-flow: column;
		grid-auto-columns: 1fr;
		grid-template-columns: none;
		gap: 26px;
	}
	.qd-flow ol:not(:has(> li:nth-child(5))) > li {
		padding: 3.2rem 1rem 1rem;
		text-align: center;
	}
	.qd-flow ol:not(:has(> li:nth-child(5))) > li::before {
		right: 50%;
		transform: translateX(50%);
	}
	/* سهم أفقي نحو الخطوة التالية (يساراً في RTL) */
	.qd-flow ol:not(:has(> li:nth-child(5))) > li:not(:last-child)::after {
		content: '';
		top: 50%;
		right: auto;
		left: -22px;
		bottom: auto;
		width: 18px;
		height: 18px;
		background: none;
		border-top: 2px solid var(--qd-blue);
		border-left: 2px solid var(--qd-blue);
		transform: translateY(-50%) rotate(-45deg);
		opacity: .7;
	}
}

/* ---------- طبقات: من الأعلى (الأقرب للمستخدم) إلى الأساس ---------- */
.qd-layers ul { display: grid; gap: 8px; }
.qd-layers li {
	position: relative;
	padding: .85rem 1.1rem;
	border-radius: 12px;
	background: var(--qd-card);
	border: 1px solid var(--qd-line);
	border-right: 5px solid var(--qd-blue);
	display: grid;
	grid-template-columns: minmax(120px, 30%) 1fr;
	gap: .2rem 1rem;
	align-items: baseline;
}
.qd-layers li span { margin-top: 0; }
.qd-layers li:nth-child(2) { border-right-color: color-mix(in srgb, var(--qd-blue) 78%, var(--qd-amber)); }
.qd-layers li:nth-child(3) { border-right-color: color-mix(in srgb, var(--qd-blue) 55%, var(--qd-amber)); }
.qd-layers li:nth-child(4) { border-right-color: color-mix(in srgb, var(--qd-blue) 35%, var(--qd-amber)); }
.qd-layers li:nth-child(n+5) { border-right-color: var(--qd-amber); }
@media (max-width: 560px) {
	.qd-layers li { grid-template-columns: 1fr; }
}

/* ---------- مقارنة ---------- */
.qd-compare {
	display: flex;
	flex-wrap: wrap;
	gap: 14px;
}
.qd-compare > .qd-title { flex-basis: 100%; margin-bottom: 0; }
.qd-compare > .qd-col { flex: 1 1 210px; }
.qd-col {
	background: var(--qd-card);
	border: 1px solid var(--qd-line);
	border-top: 4px solid var(--qd-blue);
	border-radius: 12px;
	padding: 1rem 1.1rem;
}
.qd-col:nth-of-type(3) { border-top-color: var(--qd-amber); }
.qd-col:nth-of-type(4) { border-top-color: var(--qd-green); }
.qd-col h4 {
	margin: 0 0 .6rem;
	font-size: 1.02rem;
	font-weight: 800;
	color: var(--qd-ink);
}
.qd-col li {
	position: relative;
	padding-right: 1.1rem;
	margin-bottom: .45rem;
	font-size: .92rem;
	line-height: 1.75;
	color: var(--qd-ink);
}
.qd-col li::before {
	content: '';
	position: absolute;
	right: 0;
	top: .72em;
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--qd-blue);
}
.qd-col:nth-of-type(3) li::before { background: var(--qd-amber); }
.qd-col:nth-of-type(4) li::before { background: var(--qd-green); }

/* ---------- ملاحظة / تحذير ---------- */
.qd-note, .qd-warn {
	margin: 1.6rem 0;
	padding: .95rem 1.15rem;
	border-radius: 12px;
	border-right: 4px solid var(--qd-blue);
	background: var(--qd-blue-soft);
	color: var(--qd-ink);
}
.qd-warn { border-right-color: var(--qd-amber); background: var(--qd-amber-soft); }
.qd-note p, .qd-warn p { margin: 0; line-height: 1.85; }
.qd-note p + p, .qd-warn p + p { margin-top: .5rem; }

/* ---------- Mermaid ---------- */
pre.qeeid-mermaid {
	/* يظهر كمساحة هادئة إلى أن يرسمه diagrams.js — لا يُعرض الكود الخام */
	min-height: 160px;
	margin: 2.2rem 0;
	border-radius: 16px;
	border: 1px solid #e2e8f0;
	background: linear-gradient(110deg, #f5f8fc 30%, #eef3fa 50%, #f5f8fc 70%) 0 0 / 300% 100%;
	color: transparent !important;
	font-size: 0 !important;
	overflow: hidden;
	animation: qd-shimmer 1.6s linear infinite;
}
[data-theme="dark"] pre.qeeid-mermaid {
	border-color: #2a3b54;
	background-image: linear-gradient(110deg, #141e2c 30%, #1a2638 50%, #141e2c 70%);
}
pre.qeeid-mermaid.is-failed { display: none; }
pre.qeeid-mermaid .qeeid-copy-btn { display: none; }
@keyframes qd-shimmer { to { background-position: -300% 0; } }
@media (prefers-reduced-motion: reduce) { pre.qeeid-mermaid { animation: none; } }

.qeeid-mermaid-out {
	margin: 2.2rem 0;
	padding: 1.2rem;
	background: var(--qd-bg);
	border: 1px solid var(--qd-line);
	border-radius: 16px;
	overflow-x: auto;
	text-align: center;
}
.qeeid-mermaid-out svg { max-width: 100%; height: auto; }

/* ---------- الصور الداخلية ---------- */
figure.qeeid-figure {
	margin: 2.2rem 0;
	text-align: center;
}
figure.qeeid-figure img {
	display: block;
	width: 100%;
	height: auto;
	border-radius: 14px;
	border: 1px solid #e2e8f0;
}
[data-theme="dark"] figure.qeeid-figure img { border-color: #2a3b54; }
figure.qeeid-figure figcaption {
	margin-top: .65rem;
	font-size: .86rem;
	line-height: 1.7;
	color: #64748b;
}
[data-theme="dark"] figure.qeeid-figure figcaption { color: #a5b4c9; }
