/* ==========================================================================
   Cognitive Pharmacy - شبكة الكتب مع الفلاتر (cp_books_shop)
   ملف مستقل بذاته (لا يعتمد على cp-templates.css) لأن هذا الويدجت يُستخدم داخل
   صفحة Elementor عادية، وليس ضمن سياق صفحة الكتاب المفردة فقط.
   ========================================================================== */

.cp-shop {
	--cp-bg: #fbf6ee;
	--cp-bg-alt: #f2e9d8;
	--cp-surface: #ffffff;
	--cp-text: #2b241d;
	--cp-text-muted: #6b5d4f;
	--cp-border: #e7dcc8;
	--cp-accent: #b9714b;
	--cp-accent-dark: #8f5730;
	--cp-heading-font: 'El Messiri', serif;
	--cp-body-font: 'Tajawal', sans-serif;

	font-family: var(--cp-body-font);
	color: var(--cp-text);
}

.cp-shop * {
	box-sizing: border-box;
}

.cp-shop__form {
	width: 100%;
}

.cp-shop__layout {
	display: grid;
	grid-template-columns: 260px 1fr;
	gap: 32px;
	align-items: start;
}

.cp-shop__sidebar {
	order: 0;
}

.cp-shop__main {
	order: 1;
	min-width: 0; /* يمنع فيض شبكة الكتب أفقيًا خارج عمود الـ grid على الشاشات الضيقة */
}

/* احتياطي فقط: القيمة الفعلية القابلة للتخصيص من لوحة تحكم الويدجت (نقطة انطواء
   الفلاتر) تُطبع كوسم <style> خاص بكل نسخة عبر CP_Books_Shop::render_responsive_style()
   وتتفوّق دائمًا على هذه القاعدة بفضل دقة محدّد الـ ID. تبقى هذه القاعدة فقط لضمان شكل
   سليم حتى قبل أن يُعاد حفظ الويدجت بالإعداد الجديد. */
@media (max-width: 782px) {
	.cp-shop__layout {
		grid-template-columns: 1fr;
	}
}

/* -------------------------------------------------------------------------
   الشريط الجانبي
   ------------------------------------------------------------------------- */

.cp-shop__sidebar {
	background-color: var(--cp-surface);
	border: 1px solid var(--cp-border);
	border-radius: 14px;
}

.cp-shop__sidebar-toggle {
	display: none;
	align-items: center;
	gap: 10px;
	padding: 16px 18px;
	cursor: pointer;
	font-family: var(--cp-heading-font);
	font-weight: 600;
	font-size: 16px;
	list-style: none;
}

.cp-shop__sidebar-toggle::-webkit-details-marker {
	display: none;
}

.cp-shop__sidebar-inner {
	padding: 20px;
}

@media (max-width: 782px) {
	.cp-shop__sidebar-toggle {
		display: flex;
		border-bottom: 1px solid var(--cp-border);
	}

	.cp-shop__sidebar:not([open]) .cp-shop__sidebar-toggle {
		border-bottom: none;
	}

	.cp-shop__sidebar-inner {
		padding: 16px 18px 20px;
	}
}

.cp-shop__clear-filters {
	display: none;
	align-items: center;
	justify-content: space-between;
	font-size: 13px;
	color: var(--cp-accent-dark);
	text-decoration: none;
	margin-bottom: 18px;
	padding-bottom: 14px;
	border-bottom: 1px solid var(--cp-border);
}

.cp-shop__clear-filters.is-visible {
	display: flex;
}

.cp-shop__clear-filters:hover {
	text-decoration: underline;
}

.cp-shop__filter-group {
	margin-bottom: 22px;
}

.cp-shop__filter-group:last-child {
	margin-bottom: 0;
}

.cp-shop__filter-title {
	font-family: var(--cp-heading-font);
	font-size: 15px;
	font-weight: 600;
	margin: 0 0 12px;
	color: var(--cp-text);
}

.cp-shop__filter-list {
	list-style: none;
	margin: 0;
	padding: 0;
}

.cp-shop__filter-item {
	margin-bottom: 4px;
	padding-inline-start: calc(var(--cp-depth, 0) * 16px);
}

.cp-shop__filter-item label {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 5px 2px;
	cursor: pointer;
	font-size: 13px;
}

.cp-shop__filter-item input[type="checkbox"] {
	width: 16px;
	height: 16px;
	flex-shrink: 0;
	cursor: pointer;
}

.cp-shop__filter-label {
	flex: 1;
	color: var(--cp-text);
}

.cp-shop__filter-count {
	color: var(--cp-text-muted);
	font-size: 12px;
}

/* -------------------------------------------------------------------------
   شريط الأدوات (بحث + ترتيب)
   ------------------------------------------------------------------------- */

.cp-shop__toolbar {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 14px;
	margin-bottom: 24px;
}

.cp-shop__search {
	position: relative;
	flex: 1;
	min-width: 220px;
	display: flex;
}

.cp-shop__search-input {
	flex: 1;
	height: 48px;
	border: 1px solid var(--cp-border);
	background-color: var(--cp-surface);
	border-radius: 10px 0 0 10px;
	padding: 0 16px;
	font-family: var(--cp-body-font);
	font-size: 14px;
	color: var(--cp-text);
}

.cp-shop__search-input:focus {
	outline: none;
	border-color: var(--cp-accent);
}

.cp-shop__search-btn {
	width: 52px;
	height: 48px;
	border: 1px solid var(--cp-accent);
	background-color: var(--cp-accent);
	color: #fff;
	border-radius: 0 10px 10px 0;
	cursor: pointer;
	flex-shrink: 0;
}

.cp-shop__sort {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 13px;
	color: var(--cp-text-muted);
}

.cp-shop__sort select {
	height: 48px;
	border: 1px solid var(--cp-border);
	background-color: var(--cp-surface);
	border-radius: 10px;
	padding: 0 14px;
	font-family: var(--cp-body-font);
	font-size: 13px;
	color: var(--cp-text);
	cursor: pointer;
}

@media (max-width: 480px) {
	.cp-shop__toolbar {
		flex-direction: column;
		align-items: stretch;
	}

	.cp-shop__sort select {
		width: 100%;
	}
}

/* -------------------------------------------------------------------------
   حالة عدم وجود نتائج
   ------------------------------------------------------------------------- */

.cp-shop .cp-empty-state {
	text-align: center;
	padding: 60px 20px;
	color: var(--cp-text-muted);
	background-color: var(--cp-surface);
	border: 1px dashed var(--cp-border);
	border-radius: 14px;
}

.cp-shop__results-count {
	font-size: 13px;
	color: var(--cp-text-muted);
	margin: 0 0 16px;
}

/* -------------------------------------------------------------------------
   حالة التحميل (تحسين AJAX الاختياري - راجع assets/js/cp-books-shop.js)
   ------------------------------------------------------------------------- */

.cp-shop__results {
	position: relative;
	min-height: 60px;
	transition: opacity .15s ease;
}

.cp-shop__results.is-loading {
	opacity: .45;
	pointer-events: none;
}

.cp-shop__results.is-loading::after {
	content: '';
	position: absolute;
	top: 40px;
	left: 50%;
	width: 32px;
	height: 32px;
	margin-inline-start: -16px;
	border: 3px solid var(--cp-border);
	border-top-color: var(--cp-accent);
	border-radius: 50%;
	animation: cp-shop-spin .7s linear infinite;
}

@keyframes cp-shop-spin {
	to {
		transform: rotate(360deg);
	}
}

/* -------------------------------------------------------------------------
   ترقيم الصفحات
   ------------------------------------------------------------------------- */

.cp-shop .cp-pagination {
	display: flex;
	flex-wrap: wrap;
	justify-content: center;
	gap: 8px;
	margin-top: 40px;
}

.cp-shop .cp-pagination a,
.cp-shop .cp-pagination span {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 38px;
	height: 38px;
	padding: 0 10px;
	border-radius: 8px;
	border: 1px solid var(--cp-border);
	color: var(--cp-text);
	text-decoration: none;
	font-size: 14px;
	background-color: var(--cp-surface);
}

.cp-shop .cp-pagination a:hover {
	background-color: var(--cp-accent);
	border-color: var(--cp-accent);
	color: #fff;
}

.cp-shop .cp-pagination .current {
	background-color: var(--cp-text);
	border-color: var(--cp-text);
	color: #fff;
}

.cp-shop .cp-pagination__dots {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 20px;
	color: var(--cp-text-muted);
}
