/*
 * Sklep — szuflada koszyka (plan B: <dialog id="ts-cart-drawer">, inc/shop-product.php) i przycisk koszyka w nagłówku (#ts-cart-toggle).
 * Projekt: design-ref/sklep-projekt/SKLEP-PROJEKT.md §5 (makiety final/drawer-1440.png, drawer-390*.png; źródło final/_zrodla/src/drawer.css).
 * Ładowany na każdej stronie (przycisk koszyka jest w nagłówku globalnym). Zachowanie: assets/js/shop/cart-drawer.js.
 * Komponenty: ts-cta, ts-qty--sm, ts-textbtn, ts-btn-outline--error, ts-notice, ts-medal, ts-ph — components.css.
 */

/* ---------- Przycisk koszyka w nagłówku (wygląd: .ts-cartbtn + layout.css .ts-header__cart) ---------- */

/* Bez JS szuflada się nie otworzy — zostaje link do /koszyk/ (layout.css pokazuje .ts-cartbtn--nojs) */
html:not(.ts-js) body:not(.editor-styles-wrapper) .ts-header__cart #ts-cart-toggle {
	display: none;
}

.ts-header__cart #ts-cart-toggle .ts-cartbtn__icon,
.ts-header__cart .ts-cartbtn--nojs .ts-cartbtn__icon {
	width: 22px;
	height: 22px;
}

/* ---------- Panel ---------- */

.ts-drawer {
	position: fixed;
	inset: 0 0 0 auto;
	box-sizing: border-box;
	width: 440px;
	max-width: 100vw;
	height: 100vh;
	height: 100dvh;
	max-height: none;
	margin: 0 0 0 auto;
	padding: 0;
	overflow: hidden;
	border: 0;
	background-color: var(--wp--preset--color--background);
	box-shadow: -20px 0 60px rgba(16, 43, 40, 0.25);
	color: var(--wp--preset--color--body-text);
	font-family: var(--wp--preset--font-family--sans);
	font-size: 16px;
	line-height: 1.7;
}

.ts-drawer::backdrop {
	background-color: rgba(16, 43, 40, 0.55);
}

@media (prefers-reduced-motion: no-preference) {
	.ts-drawer[open] {
		animation: ts-drawer-in 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
	}
}

@keyframes ts-drawer-in {
	from {
		transform: translateX(100%);
	}

	to {
		transform: none;
	}
}

html.ts-drawer-open {
	overflow: hidden;
}

.ts-drawer :where(h2, h3, p, ul, dl, dd) {
	margin: 0;
}

.ts-drawer__panel {
	display: flex;
	flex-direction: column;
	height: 100%;
}

/* Stany: filled / empty (atrybut data-state na dialogu) */
.ts-drawer[data-state="empty"] [data-when="filled"],
.ts-drawer:not([data-state="empty"]) [data-when="empty"] {
	display: none;
}

/* ---------- Nagłówek ---------- */

.ts-drawer__head {
	position: relative;
	isolation: isolate;
	overflow: hidden;
	display: flex;
	flex: none;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 16px 20px 16px 24px;
	background-color: var(--wp--preset--color--primary);
}

.ts-drawer__head::after {
	content: "";
	position: absolute;
	z-index: -1;
	top: -30px;
	right: 40px;
	width: 140px;
	height: 118px;
	background: var(--ts-deco-leaf-3) no-repeat center / 140px auto;
	opacity: 0.35;
	pointer-events: none;
}

.ts-drawer__title {
	color: var(--wp--preset--color--white);
	font-size: 24px;
	font-weight: 600;
	line-height: 1.2;
}

.ts-drawer__title em {
	margin-left: 4px;
	color: var(--wp--preset--color--white);
	font-family: var(--wp--preset--font-family--serif);
	font-size: 19px;
	font-style: italic;
	font-weight: 400;
}

.ts-drawer__title:focus,
.ts-drawer__empty-title:focus {
	outline: none;
}

.ts-drawer__title:focus-visible {
	outline: 2px solid var(--wp--preset--color--accent-on-dark);
	outline-offset: 4px;
}

.ts-drawer__empty-title:focus-visible {
	outline: 2px solid var(--wp--preset--color--primary);
	outline-offset: 4px;
}

.ts-drawer__close {
	display: grid;
	flex: none;
	place-items: center;
	width: 44px;
	height: 44px;
	margin: 0;
	padding: 0;
	border: 1px solid rgba(255, 255, 255, 0.8);
	border-radius: 50%;
	background: transparent;
	color: var(--wp--preset--color--white);
	cursor: pointer;
}

.ts-drawer__close::before {
	content: "";
	width: 20px;
	height: 20px;
	background-color: currentColor;
	-webkit-mask: url("../icons/close.svg") center / contain no-repeat;
	mask: url("../icons/close.svg") center / contain no-repeat;
}

.ts-drawer__close:focus-visible {
	outline-offset: 2px;
}

@media (hover: hover) {
	.ts-drawer__close:hover {
		background-color: var(--wp--preset--color--white);
		color: var(--wp--preset--color--primary);
	}
}

/* ---------- Treść (przewijana) ---------- */

.ts-drawer__body {
	display: grid;
	flex: 1 1 auto;
	align-content: start;
	gap: 16px;
	min-height: 0;
	padding: 20px 24px 24px;
	overflow-y: auto;
	overscroll-behavior: contain;
}

.ts-drawer__err p + .ts-btn-outline {
	margin-top: 10px;
}

.ts-drawer__err .ts-btn-outline {
	justify-self: start;
	min-height: 44px;
	font-size: 14px;
}

.ts-drawer__err .ts-btn-outline::before {
	content: "";
	flex: none;
	width: 18px;
	height: 18px;
	background-color: currentColor;
	-webkit-mask: url("../icons/refresh.svg") center / contain no-repeat;
	mask: url("../icons/refresh.svg") center / contain no-repeat;
}

.ts-lines {
	display: grid;
	gap: 12px;
	padding: 0;
	list-style: none;
	transition: opacity 0.2s ease;
}

.ts-lines[aria-busy="true"] {
	opacity: 0.55;
	pointer-events: none;
}

.ts-line {
	display: grid;
	grid-template-columns: 80px minmax(0, 1fr);
	gap: 16px;
	margin: 0;
	padding: 16px;
	border-radius: var(--ts-radius-card);
	background-color: var(--wp--preset--color--white);
	box-shadow: var(--ts-shadow-card);
}

/* Miniatura na kremowym tle (tło na opakowaniu — packshot JPG na białym tle wtapia się przez multiply) */
:is(.ts-line__media, .ts-emptycard__media) {
	display: block;
	box-sizing: border-box;
	width: 80px;
	height: 80px;
	padding: 6px;
	border-radius: 14px;
	background-color: var(--wp--preset--color--secondary);
}

:is(.ts-line__img, .ts-emptycard__img) {
	display: block;
	width: 100%;
	height: 100%;
	object-fit: contain;
	mix-blend-mode: multiply;
}

.ts-line__main {
	min-width: 0;
}

.ts-line__top {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 12px;
}

.ts-line__name {
	color: var(--wp--preset--color--primary);
	font-size: 16px;
	font-weight: 600;
	line-height: 1.35;
	text-decoration: none;
}

.ts-line__name:is(:hover, :focus-visible) {
	text-decoration: underline;
	text-underline-offset: 3px;
}

.ts-line__sum {
	color: var(--wp--preset--color--primary);
	font-size: 16px;
	font-weight: 700;
	line-height: 1.35;
	white-space: nowrap;
}

.ts-line__unit {
	margin-top: 2px !important;
	color: var(--ts-muted);
	font-size: 14px;
	line-height: 1.4;
}

.ts-line__actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	margin-top: 10px;
}

/* Podpowiedź pod steperem: „Maksymalna ilość to 10.” po korekcie wpisanej wartości (cart-drawer.js, F11). */
.ts-line__hint {
	margin-top: 6px !important;
}

.ts-line__remove.ts-textbtn {
	font-size: 14px;
}

.ts-line__remove::before {
	content: "";
	flex: none;
	width: 18px;
	height: 18px;
	background-color: currentColor;
	-webkit-mask: url("../icons/trash.svg") center / contain no-repeat;
	mask: url("../icons/trash.svg") center / contain no-repeat;
}

.ts-dinfo {
	display: grid;
	gap: 10px;
	padding: 4px 2px 0;
	list-style: none;
}

.ts-dinfo li {
	display: grid;
	grid-template-columns: 20px minmax(0, 1fr);
	gap: 10px;
	margin: 0;
	font-size: 14px;
	line-height: 1.55;
}

.ts-dinfo li::before {
	content: "";
	width: 20px;
	height: 20px;
	margin-top: 1px;
	background-color: var(--wp--preset--color--accent-text);
	-webkit-mask: url("../icons/truck.svg") center / contain no-repeat;
	mask: url("../icons/truck.svg") center / contain no-repeat;
}

.ts-dinfo li.ts-dinfo--return::before {
	-webkit-mask-image: url("../icons/return.svg");
	mask-image: url("../icons/return.svg");
}

.ts-dinfo b {
	color: var(--wp--preset--color--primary);
}

.ts-drawer .ts-link {
	color: var(--wp--preset--color--primary);
	font-weight: 600;
	text-decoration: underline;
	text-decoration-thickness: 1px;
	text-underline-offset: 3px;
}

.ts-drawer .ts-link:is(:hover, :focus-visible) {
	text-decoration-thickness: 2px;
}

/* ---------- Stopka (przyklejona) ---------- */

.ts-drawer__foot {
	display: grid;
	flex: none;
	gap: 12px;
	padding: 16px 24px calc(14px + env(safe-area-inset-bottom));
	background-color: var(--wp--preset--color--white);
	box-shadow: 0 -12px 30px rgba(16, 43, 40, 0.08);
}

.ts-totals {
	display: grid;
	gap: 4px;
}

.ts-totals > div {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 12px;
}

.ts-totals dt {
	font-size: 15px;
	line-height: 1.5;
}

.ts-totals dd {
	color: var(--wp--preset--color--primary);
	font-size: 15px;
	font-weight: 600;
	line-height: 1.5;
	white-space: nowrap;
}

.ts-totals .ts-totals__grand {
	margin-top: 6px;
	padding-top: 10px;
	border-top: 1px solid var(--ts-line);
}

.ts-totals__grand dt {
	color: var(--wp--preset--color--primary);
	font-size: 17px;
	font-weight: 700;
	line-height: 1.3;
}

.ts-totals__grand dd {
	font-size: 24px;
	font-weight: 700;
	line-height: 1.2;
}

.ts-totals__vat :is(dt, dd) {
	color: var(--ts-muted);
	font-size: 13px;
	font-weight: 400;
	line-height: 1.5;
}

.ts-totals__vat dt {
	white-space: nowrap;
}

.ts-totals__vat dd {
	text-align: right;
	white-space: normal;
}

.ts-drawer__foot .ts-drawer__back {
	width: 100%;
	margin-top: -4px;
}

/* ---------- Stan pusty (§5.4) ---------- */

.ts-drawer__empty {
	justify-items: center;
	padding-top: 40px;
	text-align: center;
}

.ts-drawer__empty .ts-drawer__empty-medal {
	--ts-medal-icon: url("../icons/bag.svg");
}

.ts-drawer__empty-title {
	color: var(--wp--preset--color--primary);
	font-size: 22px;
	font-weight: 700;
	line-height: 1.3;
}

.ts-emptycard {
	display: grid;
	grid-template-columns: 88px minmax(0, 1fr);
	align-items: center;
	gap: 16px;
	box-sizing: border-box;
	width: 100%;
	padding: 16px;
	border-radius: var(--ts-radius-card);
	background-color: var(--wp--preset--color--white);
	box-shadow: var(--ts-shadow-card);
	text-align: left;
}

.ts-emptycard__media.ts-emptycard__media {
	width: 88px;
	height: 88px;
}

.ts-emptycard__name {
	color: var(--wp--preset--color--primary);
	font-size: 16px;
	font-weight: 600;
	line-height: 1.35;
}

.ts-emptycard__price {
	margin-top: 2px !important;
	font-size: 14px;
	line-height: 1.6;
}

.ts-emptycard__price b {
	color: var(--wp--preset--color--primary);
	font-size: 16px;
}

.ts-emptycard__ph {
	margin: 4px 0 0 !important;
}

.ts-emptycard .ts-cta {
	margin-top: 10px;
}

.ts-drawer__goto svg {
	width: 18px;
	height: 18px;
}

/* ---------- Niskie okno (powiększenie 200% na laptopie, telefon poziomo) ----------
   Przyklejona stopka (≈ 260–300 px) zostawiała na treść 36–120 px — cały panel przewija się razem,
   nagłówek z „Zamknij koszyk” zostaje przyklejony, fokus nie chowa się pod nim (1.4.10, 2.4.11). */

@media (max-height: 600px) {
	.ts-drawer__panel {
		overflow-y: auto;
		overscroll-behavior: contain;
		scroll-padding-top: 84px;
	}

	.ts-drawer__head {
		position: sticky;
		z-index: 2;
		top: 0;
	}

	.ts-drawer__body {
		flex: none;
		overflow: visible;
	}
}

/* ---------- Telefon ---------- */

@media (max-width: 767px) {
	.ts-drawer {
		width: 100vw;
	}

	.ts-drawer__head {
		padding: 12px 14px 12px 20px;
	}

	.ts-drawer__title {
		font-size: 22px;
	}

	.ts-drawer__body {
		padding: 16px 16px 20px;
	}

	.ts-drawer__foot {
		gap: 10px;
		padding: 14px 16px calc(12px + env(safe-area-inset-bottom));
	}

	.ts-line {
		grid-template-columns: 64px minmax(0, 1fr);
		gap: 12px;
		padding: 14px;
	}

	.ts-line__media {
		width: 64px;
		height: 64px;
	}

	.ts-line__name {
		font-size: 15px;
	}

	.ts-totals__grand dd {
		font-size: 22px;
	}

	.ts-emptycard {
		grid-template-columns: 72px minmax(0, 1fr);
	}

	.ts-emptycard__media.ts-emptycard__media {
		width: 72px;
		height: 72px;
	}
}

.ts-emptycard__error {
	margin-top: 8px !important;
	color: var(--ts-error);
	font-size: 14px;
	font-weight: 600;
	line-height: 1.45;
}

.ts-emptycard__error:empty {
	display: none;
}

/* ---------- Tabela wariantów (fundament, global-shop-components.css) — dodatki zespołu produktu (ZW-07) ----------
   Cena za litr w komórce ceny (filtr thesybin_shop_variants_unit_prices, inc/shop-product.php): P1, P9 i pusta szuflada.
   Tu, a nie w CSS strony produktu, bo tabela jest też w szufladzie na każdej stronie. */

.ts-variants .ts-variants__amount {
	display: block;
}

.ts-variants .ts-variants__unit {
	display: block;
	margin-top: 2px;
	color: var(--ts-muted);
	font-size: 13px;
	font-weight: 400;
	line-height: 1.35;
	white-space: nowrap;
}

:is(.ts-on-dark, .ts-surface-dark, .has-primary-background-color) .ts-variants .ts-variants__unit {
	color: rgba(255, 255, 255, 0.85); /* na #274A46 + 6% bieli: 7.5:1 */
}

/* Pusta szuflada produktu zmiennego: karty wariantów na pełną szerokość panelu, tekst do lewej */
.ts-drawer__empty .ts-drawer__variants {
	text-align: left;
}
