/**
 * HalalEco Cart Design
 *
 * Restyles Themify Ultra's own slide-out cart (#slide-cart). Themify's
 * markup, templates and cart AJAX are left exactly as they are — this
 * only re-lays them out and adds the two elements Themify does not
 * render (unit price and line total).
 */

#slide-cart {
	--hcd-green: var( --hqs-green, #5da22b );
	--hcd-green-dark: var( --hqs-green-dark, #4c8a22 );
	--hcd-line: #e6e6e6;
	--hcd-muted: #8a8a8a;
	--hcd-pad: 24px;
	--hcd-width: 420px;
	--hcd-radius: 8px;
}

/* ------------------------------------------------------------------ *
 * Layout — this is what fixes the cut-off footer.
 *
 * Themify gives #slide-cart 50px of top padding and then puts a child
 * (#shopdock-ultra) inside it at height:100%. The child is therefore
 * 50px taller than the space available, so the bottom of the drawer —
 * the total and the checkout button — is pushed past the viewport.
 * Making the middle of the stack flex instead of height:100% keeps the
 * footer on screen at any height.
 * ------------------------------------------------------------------ */

/**
 * IMPORTANT: `display` on #slide-cart is Themify's business, never ours.
 *
 * Setting it here is how v1.0.0 pinned the drawer open over the page. But
 * depending on it is just as bad: whether Themify opens the drawer with
 * display:flex, display:block or an inline style is not something this
 * plugin can know. So the column layout starts one level down, on
 * #shopdock-ultra, which only needs its parent to have a definite height
 * — and #slide-cart is position:fixed with a height, so it always does.
 * That works identically whether the drawer opens as block or as flex.
 */
#slide-cart.sidemenu {
	width: var( --hcd-width );
	max-width: 100%;
	height: 100%;
	height: 100dvh;
	padding: 0;
	overflow: hidden;
	background: #fff;
}

#slide-cart #shopdock-ultra {
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	height: 100%;
	max-height: 100%;
	min-height: 0;
	overflow: hidden;
}

#slide-cart #cart-wrap {
	display: flex;
	flex: 1 1 auto;
	flex-direction: column;
	height: 100%;
	max-height: 100%;
	min-height: 0;
	padding: 0;
	overflow: hidden;
}

#slide-cart .cart-scroll-body {
	flex: 1 1 auto;
	min-height: 0;
	padding: 0 var( --hcd-pad );
	overflow-x: hidden;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
}

/**
 * Themify lays this out as a flex row (total on the left, button on the
 * right), which squeezes the total to its content width — that is why
 * "Total10,98 €View Cart" ran together. Force a plain block so both rows
 * are full width. Extra id in the selector so it beats the theme's.
 */
#slide-cart #cart-wrap .cart-total-checkout-wrap {
	position: static;
	display: block;
	flex: 0 0 auto;
	width: auto;
	margin: 0;
	padding: 18px var( --hcd-pad );
	padding-bottom: calc( 18px + env( safe-area-inset-bottom, 0px ) );
	border-top: 1px solid var( --hcd-line );
	background: #fff;
}

/* The WP admin bar shortens the viewport for logged-in users. */
body.admin-bar #slide-cart.sidemenu {
	height: calc( 100dvh - 32px );
}

@media screen and ( max-width: 782px ) {
	body.admin-bar #slide-cart.sidemenu {
		height: calc( 100dvh - 46px );
	}
}

/* ------------------------------------------------------------------ *
 * Header
 * ------------------------------------------------------------------ */

#slide-cart .hcd-head {
	display: flex;
	flex: 0 0 auto;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 22px var( --hcd-pad ) 18px;
	border-bottom: 1px solid var( --hcd-line );
}

#slide-cart .hcd-title {
	margin: 0;
	color: #111;
	font-size: 30px;
	font-weight: 700;
	line-height: 1.15;
}

#slide-cart #cart-icon-close.tf_close {
	position: static;
	flex: 0 0 auto;
	width: 34px;
	height: 34px;
	margin: 0;
	padding: 0;
	border: 0;
	background: none;
	color: #111;
	font-size: 0;
	line-height: 1;
	opacity: 1;
	cursor: pointer;
}

#slide-cart #cart-icon-close.tf_close::before,
#slide-cart #cart-icon-close.tf_close::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 20px;
	height: 2px;
	margin: -1px 0 0 -10px;
	background: #111;
	border-radius: 2px;
}

#slide-cart #cart-icon-close.tf_close {
	position: relative;
}

#slide-cart #cart-icon-close.tf_close::before {
	transform: rotate( 45deg );
}

#slide-cart #cart-icon-close.tf_close::after {
	transform: rotate( -45deg );
}

#slide-cart #cart-icon-close.tf_close:hover {
	opacity: 0.6;
}

/* ------------------------------------------------------------------ *
 * Line items
 * ------------------------------------------------------------------ */

#slide-cart #cart-list {
	padding: 0;
}

#slide-cart #cart-list .product {
	position: relative;
	display: grid;
	grid-template-columns: 64px minmax( 0, 1fr ) auto;
	align-items: center;
	gap: 0 16px;
	margin: 0;
	padding: 20px 0;
	border-bottom: 1px solid var( --hcd-line );
	list-style: none;
}

#slide-cart #cart-list .product:last-child {
	border-bottom: 0;
}

#slide-cart #cart-list .product-image {
	grid-column: 1;
	grid-row: 1;
	width: 64px;
	height: 64px;
	margin: 0;
	overflow: hidden;
	border-radius: 6px;
}

#slide-cart #cart-list .product-image a,
#slide-cart #cart-list .product-image img {
	display: block;
	width: 100%;
	height: 100%;
	margin: 0;
	object-fit: cover;
}

#slide-cart #cart-list .product-details {
	grid-column: 2;
	grid-row: 1;
	min-width: 0;
	padding: 0;
}

#slide-cart #cart-list .product-title {
	margin: 0;
	color: #111;
	font-size: 17px;
	font-weight: 700;
	line-height: 1.3;
}

#slide-cart #cart-list .product-title a {
	color: inherit;
	text-decoration: none;
}

#slide-cart #cart-list .hcd-unit {
	display: block;
	margin: 3px 0 10px;
	color: var( --hcd-muted );
	font-size: 15px;
	line-height: 1.2;
}

#slide-cart #cart-list .hcd-line-total {
	grid-column: 3;
	grid-row: 1;
	align-self: center;
	color: #111;
	font-size: 17px;
	font-weight: 700;
	white-space: nowrap;
}

/* Remove link — kept for accessibility, made quiet. */
#slide-cart #cart-list .remove-item.tf_close {
	position: absolute;
	top: 18px;
	right: 0;
	width: 20px;
	height: 20px;
	background: none;
	opacity: 0;
	font-size: 0;
	transition: opacity 0.15s ease;
}

#slide-cart #cart-list .product:hover .remove-item.tf_close,
#slide-cart #cart-list .remove-item.tf_close:focus {
	opacity: 0.45;
}

/* Touch devices have no hover, so it must always be reachable there. */
@media ( hover: none ) {
	#slide-cart #cart-list .remove-item.tf_close {
		opacity: 0.4;
	}
}

#slide-cart #cart-list .remove-item.tf_close::before,
#slide-cart #cart-list .remove-item.tf_close::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 14px;
	height: 1.5px;
	margin: -1px 0 0 -7px;
	background: #111;
}

#slide-cart #cart-list .remove-item.tf_close::before {
	transform: rotate( 45deg );
}

#slide-cart #cart-list .remove-item.tf_close::after {
	transform: rotate( -45deg );
}

/* ------------------------------------------------------------------ *
 * Quantity stepper — same shape as the one on the product cards.
 * ------------------------------------------------------------------ */

#slide-cart #cart-list .product-quantity {
	margin: 0;
	padding: 0;
}

#slide-cart #cart-list .quantity {
	display: flex;
	align-items: stretch;
	width: 168px;
	max-width: 100%;
	height: 46px;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: var( --hcd-radius );
	background: var( --hcd-green );
	overflow: hidden;
}

#slide-cart #cart-list .quantity button.minus,
#slide-cart #cart-list .quantity button.plus {
	flex: 0 0 52px;
	width: 52px;
	height: auto;
	min-height: 0;
	margin: 0;
	padding: 0;
	border: 0;
	border-radius: 0;
	background: var( --hcd-green );
	box-shadow: none;
	color: #fff;
	font-size: 22px;
	font-weight: 700;
	line-height: 1;
	text-shadow: none;
	cursor: pointer;
	transition: background 0.15s ease;
	-webkit-appearance: none;
	appearance: none;
}

#slide-cart #cart-list .quantity button.minus:hover,
#slide-cart #cart-list .quantity button.plus:hover {
	background: var( --hcd-green-dark );
	color: #fff;
}

#slide-cart #cart-list .quantity input.qty {
	flex: 1 1 auto;
	width: auto;
	min-width: 0;
	height: auto;
	margin: 3px;
	padding: 0 2px;
	border: 0;
	border-radius: 3px;
	background: #fff;
	box-shadow: none;
	color: #111;
	font-size: 17px;
	font-weight: 700;
	text-align: center;
	-moz-appearance: textfield;
}

#slide-cart #cart-list .quantity input.qty::-webkit-outer-spin-button,
#slide-cart #cart-list .quantity input.qty::-webkit-inner-spin-button {
	-webkit-appearance: none;
	margin: 0;
}

/* ------------------------------------------------------------------ *
 * Footer
 * ------------------------------------------------------------------ */

#slide-cart #cart-wrap .cart-total-checkout-wrap .cart-total {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	width: 100%;
	margin: 0 0 14px;
	padding: 0;
	color: #111;
	font-size: 19px;
	font-weight: 700;
	text-align: left;
}

#slide-cart #cart-wrap .cart-total-checkout-wrap .cart-total::before {
	content: attr( data-hcd-label );
	margin-right: auto;
	font-size: 19px;
	font-weight: 700;
}

#slide-cart #cart-wrap .cart-total-checkout-wrap .cart-total .amount {
	margin-left: auto;
	font-size: 19px;
	font-weight: 700;
	text-align: right;
}

/* The design shows only the total; the "View cart" link is hidden.
   Delete this rule to bring it back. */
#slide-cart #cart-wrap .cart-total-checkout-wrap .cart-total a {
	display: none;
}

#slide-cart #cart-wrap .cart-total-checkout-wrap .checkout-button {
	display: block;
	width: 100%;
	margin: 0;
	padding: 0;
}

#slide-cart #cart-wrap .cart-total-checkout-wrap .checkout-button .button,
#slide-cart #cart-wrap .cart-total-checkout-wrap button.checkout {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	width: 100%;
	min-height: 58px;
	margin: 0;
	padding: 0 20px;
	border: 0;
	border-radius: var( --hcd-radius );
	background: var( --hcd-green );
	box-shadow: none;
	color: #fff;
	font-size: 19px;
	font-weight: 700;
	line-height: 1.2;
	text-align: center;
	text-transform: none;
	cursor: pointer;
	transition: background 0.15s ease;
}

#slide-cart #cart-wrap .cart-total-checkout-wrap .checkout-button .button::after,
#slide-cart #cart-wrap .cart-total-checkout-wrap button.checkout::after {
	content: "\2192";
	font-size: 20px;
	line-height: 1;
}

#slide-cart #cart-wrap .cart-total-checkout-wrap .checkout-button .button:hover,
#slide-cart #cart-wrap .cart-total-checkout-wrap button.checkout:hover {
	background: var( --hcd-green-dark );
	color: #fff;
}

/* Empty cart */
#slide-cart .hcd-empty {
	padding: 48px 0;
	color: var( --hcd-muted );
	font-size: 16px;
	text-align: center;
}

#slide-cart.hcd-is-empty #cart-wrap .cart-total-checkout-wrap {
	display: none;
}

/* ------------------------------------------------------------------ *
 * Small screens
 * ------------------------------------------------------------------ */

@media ( max-width: 480px ) {
	#slide-cart {
		--hcd-pad: 16px;
		--hcd-width: 100%;
	}

	#slide-cart .hcd-title {
		font-size: 24px;
	}

	#slide-cart #cart-list .product {
		grid-template-columns: 56px minmax( 0, 1fr ) auto;
		gap: 0 12px;
	}

	#slide-cart #cart-list .product-image {
		width: 56px;
		height: 56px;
	}

	#slide-cart #cart-list .quantity {
		width: 140px;
		height: 42px;
	}

	#slide-cart #cart-list .quantity button.minus,
	#slide-cart #cart-list .quantity button.plus {
		flex-basis: 42px;
		width: 42px;
	}
}

/* ------------------------------------------------------------------
   hcd-sticky-footer-fix
   Theme cache sets #slide-cart{display:none}, so the open script applies an
   inline display:block which killed the flex column. #shopdock-ultra then
   kept height:100% of the whole panel and overflowed by the height of
   .hcd-head, pushing the total + checkout footer past the clipped bottom
   edge. Force the column layout on the open state.
------------------------------------------------------------------ */

#slide-cart.sidemenu.sidemenu-on {
	display: flex !important;
	flex-direction: column;
}

#slide-cart .hcd-head {
	flex: 0 0 auto;
}

#slide-cart #cart-wrap .cart-total-checkout-wrap {
	flex: 0 0 auto;
}
