/**
 * SA Suite — فروشگاه و سبد آموزش
 * ۱) بازطراحی صفحهٔ سبد (بلوک‌های ووکامرس) به شکل فهرست کارتی
 * ۲) توست «به سبد آموزش اضافه شد»
 *
 * چیدمان جدولی بلوک‌های ووکامرس در CSS خود افزونه با اولویت بالا تعریف شده؛
 * برای تبدیل ردیف‌ها به کارت، !important روی چند خصوصیت ساختاری ناگزیر است.
 */

/* ---------------------------------------------------------------------------
 * ۱) قاب صفحه — قالب روی .alignwide حاشیهٔ منفی ۸۰ پیکسلی می‌گذارد؛ در عرض‌های
 *    کوچک کل سبد ۸۰ پیکسل به بیرون قاب می‌رود و چون body دارای overflow:clip است
 *    محتوا از دو طرف بریده می‌شود. زیر ۱۱۰۰ پیکسل حاشیه خنثی می‌شود.
 * ------------------------------------------------------------------------- */
@media (max-width: 1100px) {
	.wp-block-woocommerce-cart.alignwide,
	.wp-block-woocommerce-checkout.alignwide {
		margin-inline: 0;
	}
}

.wp-block-woocommerce-cart,
.wp-block-woocommerce-checkout {
	max-width: 100%;
}

.wp-block-woocommerce-cart {
	--sac-line: rgba(var(--sa-border-rgb, 29, 29, 27), 0.12);
	--sac-line-soft: rgba(var(--sa-border-rgb, 29, 29, 27), 0.07);
	--sac-card: #ffffff;
}

/* ---------------------------------------------------------------------------
 * ۲) فهرست محصولات — جدول به فهرست کارتی تبدیل می‌شود
 * ------------------------------------------------------------------------- */
table.wc-block-cart-items {
	display: block !important;
	width: 100%;
	border: 0 !important;
	background: transparent;
}

table.wc-block-cart-items thead {
	display: none !important; /* سرستون‌های «محصول / جزئیات / مجموع» لازم نیستند */
}

table.wc-block-cart-items tbody {
	display: flex !important;
	flex-direction: column;
	gap: 14px;
}

table.wc-block-cart-items .wc-block-cart-items__row {
	display: grid !important;
	/* !important لازم است: ووکامرس روی همین سلکتور 80px 132px می‌گذارد. */
	grid-template-columns: 88px minmax(0, 1fr) minmax(120px, auto) !important;
	align-items: start;
	gap: 4px 16px;
	margin: 0 !important;
	padding: 16px !important;
	border: 1px solid var(--sac-line) !important;
	border-radius: var(--sa-radius, 18px);
	background: var(--sac-card);
	transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

table.wc-block-cart-items .wc-block-cart-items__row:hover {
	border-color: rgba(var(--sa-border-rgb, 29, 29, 27), 0.22) !important;
	box-shadow: 0 8px 24px rgba(29, 29, 27, 0.06);
}

table.wc-block-cart-items .wc-block-cart-items__row td {
	padding: 0 !important;
	border: 0 !important;
	background: transparent;
	vertical-align: top;
}

/* تصویر */
table.wc-block-cart-items .wc-block-cart-item__image {
	grid-column: 1 !important;
	grid-row: 1 !important;
	width: 88px !important;
}

.wc-block-cart-item__image a,
.wc-block-cart-item__image img {
	display: block;
	width: 88px;
	max-width: none;
}

.wc-block-cart-item__image img {
	height: 88px;
	object-fit: cover;
	border-radius: 12px;
	border: 1px solid var(--sac-line-soft);
	background: var(--sa-surface-1, #faf9f2);
}

/* مشخصات */
table.wc-block-cart-items .wc-block-cart-item__product {
	grid-column: 2 !important;
	grid-row: 1 !important;
	min-width: 0;
}

.wc-block-cart-items .wc-block-components-product-name {
	display: block;
	margin-bottom: 4px;
	color: var(--sa-text, #212121);
	font-size: 15.5px;
	font-weight: 700;
	line-height: 1.75;
	text-decoration: none;
}

.wc-block-cart-items .wc-block-components-product-name:hover {
	color: var(--sa-gold-dark, #efcc00);
}

/* قیمت واحد: کوچک و کم‌رنگ؛ مبلغ اصلی ستون کناری است. */
.wc-block-cart-item__prices .wc-block-components-product-price__value {
	color: var(--sa-text-dim, #757575);
	font-size: 12.5px;
	font-weight: 500;
}

.wc-block-cart-item__wrap .wc-block-components-product-metadata {
	overflow: hidden;
	display: -webkit-box;
	-webkit-line-clamp: 1;
	-webkit-box-orient: vertical;
	margin: 2px 0 0;
	color: var(--sa-text-dim, #757575);
	font-size: 12.5px;
}

.wc-block-cart-item__wrap .wc-block-components-product-metadata p {
	margin: 0;
}

/* تعداد + حذف */
.wc-block-cart-item__quantity {
	display: flex;
	align-items: center;
	gap: 12px;
	margin-top: 12px;
	padding: 0;
}

.wc-block-components-quantity-selector {
	display: flex;
	align-items: center;
	min-width: 112px;
	height: 38px;
	margin: 0;
	border: 1px solid var(--sac-line) !important;
	border-radius: 999px;
	background: var(--sa-surface-1, #faf9f2);
	overflow: hidden;
}

.wc-block-components-quantity-selector::after {
	display: none; /* خط‌های جداکنندهٔ پیش‌فرض ووکامرس */
}

.wc-block-components-quantity-selector__input {
	background: transparent;
	color: var(--sa-text, #212121);
	font-size: 14px;
	font-weight: 700;
}

.wc-block-components-quantity-selector__button {
	width: 36px;
	color: var(--sa-text-muted, #4f4f4f);
	font-size: 17px;
	font-weight: 700;
	opacity: 1;
	transition: background 0.15s ease, color 0.15s ease;
}

.wc-block-components-quantity-selector__button:hover:not(:disabled) {
	background: rgba(var(--sa-gold-rgb, 255, 218, 0), 0.35);
	color: #1d1d1b;
}

.wc-block-cart-item__remove-link {
	margin: 0 !important;
	padding: 0;
	color: var(--sa-text-dim, #757575) !important;
	font-size: 12.5px;
	text-decoration: none !important;
	transition: color 0.15s ease;
}

.wc-block-cart-item__remove-link:hover {
	color: #c0392b !important;
}

/* مبلغ ردیف */
table.wc-block-cart-items .wc-block-cart-item__total {
	grid-column: 3 !important;
	grid-row: 1 !important;
	display: flex !important;
	justify-content: flex-end;
	padding-inline-start: 8px !important;
	white-space: nowrap;
}

.wc-block-cart-item__total .wc-block-components-product-price__value {
	color: var(--sa-text, #212121);
	font-size: 16px;
	font-weight: 800;
}

/* ---------------------------------------------------------------------------
 * ۳) ستون جمع کل — کارت چسبان
 * ------------------------------------------------------------------------- */
.wc-block-cart__sidebar {
	align-self: flex-start;
}

@media (min-width: 1001px) {
	.wc-block-cart__sidebar {
		position: sticky;
		top: 96px;
	}
}

.wc-block-cart__sidebar .wp-block-woocommerce-cart-order-summary-block {
	padding: 20px;
	border: 1px solid var(--sac-line);
	border-radius: var(--sa-radius, 18px);
	background: var(--sac-card);
	box-shadow: 0 10px 30px rgba(29, 29, 27, 0.05);
}

/* عنوان با نشان زرد «خط استاندارد» */
.wc-block-cart__totals-title {
	position: relative;
	display: block;
	margin: 0 0 16px !important;
	padding: 0 0 12px;
	border-bottom: 1px solid var(--sac-line-soft);
	color: var(--sa-text, #212121);
	font-size: 16px !important;
	font-weight: 800 !important;
	letter-spacing: 0 !important;
	text-transform: none !important;
}

.wc-block-cart__totals-title::after {
	content: "";
	position: absolute;
	inset-inline-start: 0;
	bottom: -1px;
	width: 44px;
	height: 3px;
	border-radius: 3px;
	background: var(--sa-gold, #ffda00);
}

.wc-block-cart__sidebar .wc-block-components-totals-wrapper {
	padding: 12px 0;
	border-top: 0;
	border-bottom: 1px solid var(--sac-line-soft);
}

.wc-block-cart__sidebar .wc-block-components-totals-wrapper:last-of-type {
	border-bottom: 0;
}

.wc-block-components-totals-item__label {
	color: var(--sa-text-muted, #4f4f4f);
	font-size: 14px;
}

.wc-block-components-totals-footer-item {
	margin-top: 4px;
}

.wc-block-components-totals-footer-item .wc-block-components-totals-item__label {
	color: var(--sa-text, #212121);
	font-size: 15px;
	font-weight: 800;
}

.wc-block-components-totals-footer-item .wc-block-components-formatted-money-amount {
	color: var(--sa-text, #212121);
	font-size: 19px;
	font-weight: 800;
}

/* کوپن */
.wc-block-components-totals-coupon .wc-block-components-panel__button {
	color: var(--sa-text-muted, #4f4f4f);
	font-size: 13.5px;
	font-weight: 600;
}

.wc-block-components-totals-coupon .wc-block-components-panel__button:hover {
	color: var(--sa-text, #212121);
}

/* دکمهٔ تسویه */
.wc-block-cart__submit-container {
	margin-top: 16px;
	padding: 0;
}

.wc-block-cart__submit-button,
.wc-block-cart__submit-button.contained {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	width: 100%;
	min-height: 54px;
	padding: 0 20px;
	border: 0;
	border-radius: var(--sa-radius-btn, 11px);
	background: var(--sa-gold, #ffda00);
	color: #1d1d1b;
	font-family: var(--sa-font, "Vazirmatn", Tahoma, sans-serif);
	font-size: 15.5px;
	font-weight: 800;
	text-decoration: none;
	box-shadow: 0 10px 24px rgba(var(--sa-gold-rgb, 255, 218, 0), 0.35);
	transition: background 0.18s ease, transform 0.15s ease, box-shadow 0.18s ease;
}

.wc-block-cart__submit-button:hover,
.wc-block-cart__submit-button:focus {
	background: var(--sa-gold-dark, #efcc00);
	color: #1d1d1b;
	transform: translateY(-1px);
	box-shadow: 0 14px 28px rgba(var(--sa-gold-rgb, 255, 218, 0), 0.45);
}

.wc-block-cart__submit-button::after {
	content: "←";
	font-size: 17px;
	line-height: 1;
}

/* یادداشت اطمینان زیر دکمه */
.wc-block-cart__submit-container::after {
	content: "پرداخت امن • دسترسی به دوره پس از تأیید سفارش";
	display: block;
	margin-top: 10px;
	color: var(--sa-text-dim, #757575);
	font-size: 12px;
	text-align: center;
}

/* ---------------------------------------------------------------------------
 * ۴) سبد خالی
 * ------------------------------------------------------------------------- */
.wp-block-woocommerce-empty-cart-block {
	padding: 8px 0 24px;
}

.wp-block-woocommerce-empty-cart-block .wc-block-cart__empty-cart__title {
	color: var(--sa-text, #212121);
	font-size: 20px;
	font-weight: 800;
}

/* ---------------------------------------------------------------------------
 * ۵) موبایل — کارت دوستونه + نوار تسویهٔ چسبان پایین صفحه
 * ------------------------------------------------------------------------- */
@media (max-width: 700px) {
	table.wc-block-cart-items .wc-block-cart-items__row {
		grid-template-columns: 64px minmax(0, 1fr) !important;
		gap: 2px 12px;
		padding: 14px !important;
	}

	table.wc-block-cart-items .wc-block-cart-item__image,
	.wc-block-cart-item__image a,
	.wc-block-cart-item__image img {
		width: 64px !important;
	}

	.wc-block-cart-item__image img {
		height: 64px;
	}

	table.wc-block-cart-items .wc-block-cart-item__total {
		grid-column: 1 / -1 !important;
		grid-row: 2 !important;
		justify-content: flex-start;
		margin-top: 10px;
		padding-top: 10px !important;
		padding-inline-start: 0 !important;
		border-top: 1px dashed var(--sac-line-soft);
	}

	.wc-block-cart-items .wc-block-components-product-name {
		font-size: 14.5px;
	}

	.wc-block-cart__sidebar .wp-block-woocommerce-cart-order-summary-block {
		padding: 16px;
	}

	/* دکمهٔ تسویه همیشه در دسترس */
	.wc-block-cart__submit.wp-block-woocommerce-proceed-to-checkout-block {
		position: sticky;
		bottom: 0;
		z-index: 40;
		margin-inline: -10px;
		padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
		background: rgba(255, 255, 255, 0.94);
		backdrop-filter: blur(8px);
		border-top: 1px solid var(--sac-line);
	}

	.wc-block-cart__submit-container::after {
		display: none;
	}
}

/* ---------------------------------------------------------------------------
 * ۶) توست «به سبد آموزش اضافه شد» — هم‌سبک توست هدر
 * ------------------------------------------------------------------------- */
.sa-shop-toasts {
	position: fixed;
	bottom: calc(18px + env(safe-area-inset-bottom, 0px));
	left: 50%;
	z-index: 330;
	display: flex;
	flex-direction: column;
	gap: 8px;
	align-items: center;
	width: max-content;
	max-width: min(92vw, 520px);
	transform: translateX(-50%);
	pointer-events: none;
}

.sa-shop-toast {
	display: flex;
	align-items: center;
	gap: 10px;
	max-width: 100%;
	padding: 13px 16px;
	border-radius: 16px;
	background: #1d1d1b;
	color: #ffffff;
	font-family: var(--sa-font, "Vazirmatn", Tahoma, sans-serif);
	font-size: 13.5px;
	line-height: 1.6;
	direction: rtl;
	box-shadow: 0 16px 40px rgba(29, 29, 27, 0.3);
	opacity: 0;
	transform: translateY(16px);
	transition: opacity 0.25s ease, transform 0.25s ease;
	pointer-events: auto;
}

.sa-shop-toast.is-on {
	opacity: 1;
	transform: translateY(0);
}

.sa-shop-toast.is-off {
	opacity: 0;
	transform: translateY(8px);
}

.sa-shop-toast-ico {
	display: inline-flex;
	flex: 0 0 auto;
	color: var(--sa-gold, #ffda00);
}

.sa-shop-toast-text {
	min-width: 0;
	overflow: hidden;
	display: -webkit-box;
	-webkit-line-clamp: 3;
	-webkit-box-orient: vertical;
}

.sa-shop-toast-cta {
	flex: 0 0 auto;
	color: var(--sa-gold, #ffda00);
	font-weight: 700;
	text-decoration: none;
	white-space: nowrap;
}

.sa-shop-toast-cta:hover {
	text-decoration: underline;
}

.sa-shop-toast-close {
	flex: 0 0 auto;
	width: 24px;
	height: 24px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: rgba(255, 255, 255, 0.12);
	color: #ffffff;
	cursor: pointer;
}

.sa-shop-toast-close:hover {
	background: rgba(255, 255, 255, 0.22);
}

@media (max-width: 600px) {
	.sa-shop-toasts {
		width: 92vw;
	}

	/* خط اول: آیکن + متن، خط دوم: دکمهٔ مشاهدهٔ سبد.
	   دکمهٔ بستن در موبایل حذف می‌شود؛ لمس خود توست آن را می‌بندد (sa-shop.js). */
	.sa-shop-toast {
		width: 100%;
		flex-wrap: wrap;
		align-items: flex-start;
	}

	.sa-shop-toast-ico {
		margin-top: 2px;
	}

	.sa-shop-toast-text {
		flex: 1 1 0;
	}

	.sa-shop-toast-close {
		display: none;
	}

	.sa-shop-toast-cta {
		flex: 1 1 100%;
		margin-inline-start: 28px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.sa-shop-toast {
		transition: none;
	}
}
