/*
 * Slide-out cart drawer + the shared quantity control.
 *
 * Loaded globally (functions.php) because the drawer is global.
 */

/* ── Quantity control ──────────────────────────────────────────────
   Shared by the package page and the cart. The number input stays the
   source of truth; the buttons are a pointer convenience and are kept out
   of the tab order (see woocommerce/global/quantity-input.php). */

.kyrex-qty {
	display: inline-flex;
	align-items: stretch;
	border: 1px solid var(--kyrex-border);
	border-radius: var(--kyrex-radius-sm);
	background-color: var(--kyrex-surface);
	overflow: hidden;
}

.kyrex-qty__step {
	width: 2.25rem;
	border: 0;
	background: none;
	color: var(--kyrex-charcoal);
	font-family: var(--kyrex-font-body);
	font-size: 1rem;
	line-height: 1;
	cursor: pointer;
	transition: background-color 150ms ease;
}

.kyrex-qty__step:hover {
	background-color: var(--kyrex-ivory);
}

.kyrex-qty__input {
	width: 3rem;
	border: 0;
	border-inline: 1px solid var(--kyrex-border);
	background: none;
	text-align: center;
	font-family: var(--kyrex-font-body);
	font-size: 0.9375rem;
	color: var(--kyrex-charcoal);
	padding: 0.5rem 0;
	-moz-appearance: textfield;
}

/* The native spinners are the reason this control exists — hide them so the
   explicit buttons are the only affordance. */
.kyrex-qty__input::-webkit-outer-spin-button,
.kyrex-qty__input::-webkit-inner-spin-button {
	-webkit-appearance: none;
	margin: 0;
}

.kyrex-qty__input:focus-visible {
	outline: 2px solid var(--kyrex-charcoal);
	outline-offset: -2px;
}

/* ── Busy state ────────────────────────────────────────────────────
   The cart dims while a quantity change is in flight, so a slow connection
   never looks like nothing happened. */

.kyrex-cart.is-busy {
	opacity: 0.55;
	pointer-events: none;
}

.kyrex-product__submit.is-loading {
	opacity: 0.6;
	cursor: progress;
}

/* ── Drawer ────────────────────────────────────────────────────────*/

.kyrex-drawer-backdrop:not([hidden]) {
	display: block;
	position: fixed;
	inset: 0;
	z-index: 400;
	background-color: rgb(42 38 34 / 45%);
}

.kyrex-cart-drawer {
	position: fixed;
	top: 0;
	right: 0;
	bottom: 0;
	z-index: 500;
	width: min(24rem, 92vw);
	display: flex;
	flex-direction: column;
	background-color: var(--kyrex-surface);
	border-left: 1px solid var(--kyrex-border);
	/* Same 0s pattern as the navigation drawer: a transitioned `visibility`
	   stays `hidden` for the whole duration, and a hidden element cannot take
	   focus — which silently broke the nav drawer's focus trap once already. */
	transform: translateX(100%);
	visibility: hidden;
	transition: transform 260ms ease, visibility 0s 260ms;
}

body.kyrex-cart-drawer-open .kyrex-cart-drawer {
	transform: translateX(0);
	visibility: visible;
	transition: transform 260ms ease, visibility 0s 0s;
}

body.kyrex-cart-drawer-open {
	overflow: hidden;
}

.kyrex-cart-drawer__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	padding: 1.25rem 1.25rem 0.875rem;
	border-bottom: 1px solid var(--kyrex-border);
}

.kyrex-cart-drawer__title {
	font-family: var(--kyrex-font-display);
	font-size: 1.25rem;
	font-weight: 600;
	margin: 0;
	color: var(--kyrex-charcoal);
}

.kyrex-cart-drawer__close {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	padding: 0.375rem;
	background: none;
	border: 0;
	border-radius: var(--kyrex-radius-sm);
	color: var(--kyrex-charcoal);
	cursor: pointer;
}

.kyrex-cart-drawer__close:focus-visible {
	outline: 2px solid var(--kyrex-charcoal);
	outline-offset: 2px;
}

.kyrex-cart-drawer__body {
	flex: 1;
	overflow-y: auto;
	padding: 1.25rem;
}

.kyrex-cart-drawer__foot {
	display: grid;
	gap: 0.625rem;
	padding: 1.25rem;
	border-top: 1px solid var(--kyrex-border);
	background-color: var(--kyrex-ivory);
}

.kyrex-cart-drawer__action {
	width: 100%;
	text-align: center;
}

/* ── Mini-cart contents ────────────────────────────────────────────
   WooCommerce's own markup, kept in step by the fragments mechanism.

   Its child order is: remove link, then a single <a> containing the image
   AND the product name as a text node, then dl.variation, then
   span.quantity. An earlier attempt here assumed image / name / price as
   three grid children and produced a mangled row — the remove link took the
   first cell and "Date & Time" was squeezed into a 40px column that wrapped
   over eight lines. Laid out against the real shape instead. */

.kyrex-cart-drawer .woocommerce-mini-cart {
	list-style: none;
	margin: 0;
	padding: 0;
}

.kyrex-cart-drawer .woocommerce-mini-cart-item {
	position: relative;
	padding: 0.875rem 2rem 0.875rem 0;
	border-bottom: 1px solid var(--kyrex-border);
	font-family: var(--kyrex-font-body);
	font-size: 0.875rem;
}

/* The product link carries the thumbnail and the name together. */
.kyrex-cart-drawer .woocommerce-mini-cart-item > a:not(.remove) {
	display: grid;
	grid-template-columns: 3.5rem 1fr;
	gap: 0.75rem;
	align-items: start;
	color: var(--kyrex-charcoal);
	font-weight: 600;
	line-height: 1.35;
	text-decoration: none;
}

.kyrex-cart-drawer .woocommerce-mini-cart-item > a:not(.remove) img {
	width: 3.5rem;
	height: 3.5rem;
	object-fit: cover;
	border: 1px solid var(--kyrex-border);
	margin: 0;
	float: none;
}

/* Remove sits in the gutter reserved by the row's right padding, so it never
   collides with the name however long that wraps. */
.kyrex-cart-drawer .woocommerce-mini-cart-item a.remove {
	position: absolute;
	top: 0.75rem;
	right: 0;
	width: 1.5rem;
	height: 1.5rem;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-size: 1rem;
	line-height: 1;
}

/* Slot and add-ons, indented to line up with the name rather than the image.
   Deliberately NOT a grid. WooCommerce styles these with
   `.variation dt { float: left }` / `.variation dd { float: left }`, and the
   combination transposed the pairs — the value rendered to the left of its own
   label. Inline pairs with a forced break after each `dd` reads the same as the
   cart and cannot be knocked out of order by a float rule. */
.kyrex-cart-drawer .woocommerce-mini-cart-item dl.variation {
	display: block;
	margin: 0.375rem 0 0 4.25rem;
	font-size: 0.75rem;
	line-height: 1.45;
	overflow: hidden;
}

.kyrex-cart-drawer .woocommerce-mini-cart-item dl.variation dt,
.kyrex-cart-drawer .woocommerce-mini-cart-item dl.variation dd {
	float: none;
	clear: none;
	display: inline;
	margin: 0;
}

.kyrex-cart-drawer .woocommerce-mini-cart-item dl.variation dt {
	font-weight: 600;
	color: var(--kyrex-charcoal-muted);
}

.kyrex-cart-drawer .woocommerce-mini-cart-item dl.variation dd {
	color: var(--kyrex-charcoal);
}

/* One pair per line. */
.kyrex-cart-drawer .woocommerce-mini-cart-item dl.variation dd::after {
	content: '';
	display: block;
}

.kyrex-cart-drawer .woocommerce-mini-cart-item dl.variation dd p {
	display: inline;
	margin: 0;
}

.kyrex-cart-drawer .woocommerce-mini-cart-item .quantity {
	display: block;
	margin: 0.375rem 0 0 4.25rem;
	color: var(--kyrex-charcoal-muted);
	font-size: 0.8125rem;
}

.kyrex-cart-drawer .woocommerce-mini-cart__total {
	display: flex;
	justify-content: space-between;
	gap: 1rem;
	margin: 1rem 0 0;
	padding-top: 0.875rem;
	border-top: 1px solid var(--kyrex-border);
	font-family: var(--kyrex-font-body);
	font-weight: 600;
	color: var(--kyrex-charcoal);
}

.kyrex-cart-drawer .woocommerce-mini-cart__empty-message {
	font-family: var(--kyrex-font-body);
	color: var(--kyrex-charcoal-muted);
	margin: 0;
}

/* WooCommerce puts its own buttons in the mini-cart; the drawer has its own
   footer actions, so those would be a duplicate pair. */
.kyrex-cart-drawer .woocommerce-mini-cart__buttons {
	display: none;
}
