/**
 * SAMECOM side cart (drawer).
 *
 * Everything is scoped to .samecom-side-cart* so no theme rule is touched. The
 * drawer is a fixed overlay that is display:none until it opens, so it can never
 * add to the width or the height of the document.
 */

.samecom-side-cart {
	position: fixed;
	inset: 0;
	z-index: 100000;
	overflow: hidden;
}

.samecom-side-cart[hidden] { display: none; }

.samecom-side-cart__backdrop {
	position: absolute;
	inset: 0;
	background: rgba( 15, 23, 42, .5 );
	opacity: 0;
	transition: opacity .24s ease;
}

.samecom-side-cart.is-open .samecom-side-cart__backdrop { opacity: 1; }

.samecom-side-cart__panel {
	position: absolute;
	inset-block: 0;
	inset-inline-end: 0;
	display: flex;
	flex-direction: column;
	width: min( 420px, 100% );
	max-width: 100%;
	background: #fff;
	box-shadow: 0 0 40px rgba( 15, 23, 42, .22 );
	/* The drawer sits off its own edge: a logical property, so RTL slides the other way. */
	transform: translateX( 100% );
	transition: transform .24s ease;
	padding-bottom: env( safe-area-inset-bottom, 0 );
	overflow: hidden;
}

[dir="rtl"] .samecom-side-cart__panel { transform: translateX( -100% ); }

.samecom-side-cart.is-open .samecom-side-cart__panel { transform: translateX( 0 ); }

.samecom-side-cart__panel:focus-visible { outline: 3px solid color-mix( in srgb, var( --samecom-primary ) 45%, transparent ); outline-offset: -3px; }

/* ---------- head ---------- */

.samecom-side-cart__head {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 16px 18px;
	border-bottom: 1px solid var( --samecom-border, #e5e7eb );
	flex: 0 0 auto;
}

.samecom-side-cart__title { margin: 0; font-size: 1.05rem; font-weight: 700; min-width: 0; overflow-wrap: anywhere; }
.samecom-side-cart__count { color: var( --samecom-muted, #6b7280 ); font-size: .85rem; }

.samecom-side-cart__close {
	margin-inline-start: auto;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	border: 0;
	border-radius: 50%;
	background: transparent;
	color: inherit;
	cursor: pointer;
	flex: 0 0 auto;
}

.samecom-side-cart__close:hover { background: rgba( 15, 23, 42, .06 ); }

/* ---------- lines ---------- */

.samecom-side-cart__list {
	flex: 1 1 auto;
	/* The item list is the only scrolling area; the summary below stays put. */
	overflow-y: auto;
	overflow-x: hidden;
	-webkit-overflow-scrolling: touch;
	overscroll-behavior: contain;
	margin: 0;
	padding: 8px 0;
	list-style: none;
	position: relative;
}

.samecom-side-cart__line {
	display: grid;
	grid-template-columns: 64px minmax( 0, 1fr ) minmax( 64px, auto );
	gap: 12px;
	align-items: start;
	padding: 12px 18px;
	border-bottom: 1px solid var( --samecom-border, #e5e7eb );
	transition: opacity .18s ease, transform .18s ease;
}

.samecom-side-cart__line.is-busy { opacity: .6; }
.samecom-side-cart__line.is-removing { opacity: 0; transform: translateY( -6px ); }

.samecom-side-cart__media { width: 64px; height: 64px; border-radius: var( --samecom-radius-sm, 8px ); overflow: hidden; background: #f3f4f6; }
.samecom-side-cart__media img { width: 100%; height: 100%; object-fit: cover; display: block; }

.samecom-side-cart__body { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.samecom-side-cart__name { font-weight: 600; color: inherit; text-decoration: none; min-width: 0; overflow-wrap: anywhere; }
.samecom-side-cart__name:hover { text-decoration: underline; }
.samecom-side-cart__attrs { font-size: .85rem; color: var( --samecom-muted, #6b7280 ); overflow-wrap: anywhere; }
.samecom-side-cart__sku { font-size: .72rem; color: var( --samecom-muted, #6b7280 ); opacity: .75; overflow-wrap: anywhere; }
.samecom-side-cart__unit { font-size: .85rem; color: var( --samecom-muted, #6b7280 ); }
.samecom-side-cart__error { font-size: .8rem; color: #b91c1c; overflow-wrap: anywhere; }

.samecom-side-cart__controls { display: inline-flex; align-items: center; gap: 2px; margin-top: 6px; border: 1px solid var( --samecom-border, #e5e7eb ); border-radius: var( --samecom-radius-sm, 8px ); width: max-content; }

.samecom-side-cart__qty-btn {
	min-width: 36px;
	min-height: 36px;
	border: 0;
	background: transparent;
	cursor: pointer;
	font-size: 1rem;
	line-height: 1;
	color: inherit;
}

.samecom-side-cart__qty-btn:disabled { opacity: .35; cursor: not-allowed; }
.samecom-side-cart__qty-value { min-width: 28px; text-align: center; font-variant-numeric: tabular-nums; }

.samecom-side-cart__aside { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; min-width: 0; }
.samecom-side-cart__total { font-weight: 700; white-space: nowrap; }

.samecom-side-cart__remove {
	border: 0;
	background: transparent;
	color: var( --samecom-muted, #6b7280 );
	cursor: pointer;
	padding: 6px;
	border-radius: 6px;
	min-width: 32px;
	min-height: 32px;
}

.samecom-side-cart__remove:hover { color: #b91c1c; background: rgba( 185, 28, 28, .08 ); }
.samecom-side-cart__remove:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- empty / loading / undo ---------- */

.samecom-side-cart__empty { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 32px 24px; text-align: center; }
.samecom-side-cart__empty-title { margin: 0; font-weight: 700; }
.samecom-side-cart__empty-text { margin: 0; color: var( --samecom-muted, #6b7280 ); }
.samecom-side-cart__loading { flex: 1 1 auto; display: flex; align-items: center; justify-content: center; color: var( --samecom-muted, #6b7280 ); margin: 0; padding: 32px; }

.samecom-side-cart__undo { display: flex; align-items: center; gap: 10px; padding: 10px 18px; background: #f9fafb; border-top: 1px solid var( --samecom-border, #e5e7eb ); font-size: .88rem; flex: 0 0 auto; }
.samecom-side-cart__undo span { min-width: 0; overflow-wrap: anywhere; }
.samecom-side-cart__undo-btn { margin-inline-start: auto; border: 0; background: transparent; color: var( --samecom-primary, #c9080b ); font-weight: 600; cursor: pointer; text-decoration: underline; padding: 4px; min-height: 32px; flex: 0 0 auto; }

/* ---------- summary ---------- */

.samecom-side-cart__footer { flex: 0 0 auto; padding: 14px 18px calc( 14px + env( safe-area-inset-bottom, 0px ) ); border-top: 1px solid var( --samecom-border, #e5e7eb ); background: #fff; }
.samecom-side-cart__row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.samecom-side-cart__row span { min-width: 0; overflow-wrap: anywhere; }
.samecom-side-cart__row--subtotal { font-size: 1.05rem; }
.samecom-side-cart__row--saving strong { color: #15803d; }
.samecom-side-cart__note { margin: 0 0 12px; font-size: .8rem; color: var( --samecom-muted, #6b7280 ); overflow-wrap: anywhere; }
.samecom-side-cart__actions { display: flex; flex-direction: column; gap: 8px; }
.samecom-side-cart__actions .samecom-btn { width: 100%; justify-content: center; text-align: center; }
.samecom-side-cart__continue { border: 0; background: transparent; color: var( --samecom-muted, #6b7280 ); cursor: pointer; text-decoration: underline; min-height: 40px; }

/* ---------- launcher ---------- */

.samecom-side-cart-launcher {
	position: fixed;
	inset-inline-end: 16px;
	bottom: calc( 86px + env( safe-area-inset-bottom, 0px ) );
	z-index: 99990;
	width: 52px;
	height: 52px;
	border: 0;
	border-radius: 50%;
	background: var( --samecom-primary, #c9080b );
	color: #fff;
	cursor: pointer;
	box-shadow: 0 6px 20px rgba( 15, 23, 42, .25 );
}

.samecom-side-cart-launcher__icon { font-size: 1.25rem; line-height: 1; }

.samecom-side-cart-launcher__count {
	position: absolute;
	top: -4px;
	inset-inline-end: -4px;
	min-width: 20px;
	height: 20px;
	padding: 0 5px;
	border-radius: 10px;
	background: #111827;
	color: #fff;
	font-size: .72rem;
	line-height: 20px;
	text-align: center;
}

.samecom-side-cart-launcher__count[hidden] { display: none; }

/* ---------- scroll lock ---------- */

html.samecom-side-cart-locked { overflow: hidden; }
html.samecom-side-cart-locked body { position: fixed; inset-inline: 0; width: 100%; overflow: hidden; }

/* ---------- mobile ---------- */

@media ( max-width: 600px ) {
	.samecom-side-cart__panel { width: 100%; }
	.samecom-side-cart__line { grid-template-columns: 56px minmax( 0, 1fr ) minmax( 56px, auto ); padding: 12px 14px; gap: 10px; }
	.samecom-side-cart__media { width: 56px; height: 56px; }
	.samecom-side-cart__head,
	.samecom-side-cart__footer,
	.samecom-side-cart__undo { padding-inline: 14px; }
	.samecom-side-cart__qty-btn { min-width: 40px; min-height: 40px; }
}

@media ( prefers-reduced-motion: reduce ) {
	.samecom-side-cart__panel,
	.samecom-side-cart__backdrop,
	.samecom-side-cart__line { transition: none; }
}
