/**
 * AF Commerce — shared overlays and interactive components.
 *
 * Drawers, modals, the mini cart, quantity steppers, the mobile menu and the
 * bottom navigation. These are loaded on every template because any of them can
 * be opened from the header, so they are kept deliberately small.
 *
 * All overlays follow one contract: hidden by default, `.is-open` to show, a
 * backdrop that closes on click, and a panel that traps focus while open. The
 * JavaScript only toggles the class and manages focus; the presentation lives
 * entirely here.
 */

/* -------------------------------------------------------------------------
 * 1. Overlay shell
 * ---------------------------------------------------------------------- */

.af-drawer,
.af-modal {
	position: fixed;
	inset: 0;
	z-index: 100;
	visibility: hidden;
	pointer-events: none;
}

.af-drawer.is-open,
.af-modal.is-open {
	visibility: visible;
	pointer-events: auto;
}

.af-drawer__backdrop,
.af-modal__backdrop {
	position: absolute;
	inset: 0;
	border: 0;
	padding: 0;
	background: rgba(12, 14, 18, 0.45);
	opacity: 0;
	transition: opacity 0.25s ease;
	cursor: pointer;
}

.af-drawer.is-open .af-drawer__backdrop,
.af-modal.is-open .af-modal__backdrop {
	opacity: 1;
}

.af-drawer__panel {
	position: absolute;
	inset-block: 0;
	inset-inline-end: 0;
	display: flex;
	flex-direction: column;
	width: min(94vw, 420px);
	background: var(--af-background);
	box-shadow: var(--af-shadow-3);
	transform: translateX(100%);
	transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.af-drawer.is-open .af-drawer__panel {
	transform: none;
}

.af-drawer--menu .af-drawer__panel {
	inset-inline: 0 auto;
	transform: translateX(-100%);
}

.af-drawer--menu.is-open .af-drawer__panel {
	transform: none;
}

.af-drawer__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--af-space-md);
	padding: var(--af-space-md);
	border-bottom: 1px solid var(--af-border);
}

.af-drawer__title {
	margin: 0;
	font-size: var(--af-fs-h5);
}

.af-drawer__close,
.af-modal__close {
	display: grid;
	place-items: center;
	width: 40px;
	height: 40px;
	border: 0;
	border-radius: 50%;
	background: var(--af-surface);
	color: var(--af-text);
}

.af-drawer__close:hover,
.af-modal__close:hover {
	background: var(--af-border);
}

.af-drawer__body {
	flex: 1 1 auto;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: var(--af-space-md);
}

.af-drawer__footer {
	padding: var(--af-space-md);
	border-top: 1px solid var(--af-border);
}

.af-drawer__loading,
.af-modal__loading {
	display: grid;
	place-items: center;
	min-height: 180px;
	color: var(--af-muted);
	font-size: var(--af-fs-small);
}

/* Modal. */
.af-modal__panel {
	position: absolute;
	inset-block-start: 50%;
	inset-inline-start: 50%;
	width: min(94vw, 940px);
	max-height: 90vh;
	overflow-y: auto;
	overscroll-behavior: contain;
	border-radius: var(--af-radius-lg);
	background: var(--af-background);
	box-shadow: var(--af-shadow-3);
	transform: translate(-50%, -46%);
	opacity: 0;
	transition: transform 0.22s ease, opacity 0.22s ease;
}

.af-modal.is-open .af-modal__panel {
	transform: translate(-50%, -50%);
	opacity: 1;
}

.af-modal__close {
	position: absolute;
	inset-block-start: var(--af-space-sm);
	inset-inline-end: var(--af-space-sm);
	z-index: 2;
}

.af-modal__body {
	padding: var(--af-space-xl);
}

.af-modal__title {
	margin: 0 0 var(--af-space-md);
	font-size: var(--af-fs-h4);
}

/* A failed fetch is reported in place rather than silently leaving a spinner. */
.af-modal__error,
.af-drawer__error {
	margin: 0;
	padding: var(--af-space-lg);
	color: var(--af-error);
	font-size: var(--af-fs-small);
	text-align: center;
}

/*
 * Content modals hold editorial panels — size guides, shipping tables — so
 * they read as an article rather than a product dialog.
 */
.af-modal--content .af-modal__panel {
	width: min(94vw, 720px);
}

.af-modal--content .af-modal__body table {
	width: 100%;
	border-collapse: collapse;
	font-size: var(--af-fs-small);
}

.af-modal--content .af-modal__body th,
.af-modal--content .af-modal__body td {
	padding: var(--af-space-xs) var(--af-space-sm);
	border: 1px solid var(--af-border);
	text-align: start;
}

/* Scroll lock is set on the body while any overlay is open. */
body.af-overlay-open {
	overflow: hidden;
}

@media (max-width: 600px) {
	.af-modal__panel {
		inset: auto 0 0 0;
		width: 100%;
		max-height: 92vh;
		border-radius: var(--af-radius-lg) var(--af-radius-lg) 0 0;
		transform: translateY(100%);
	}

	.af-modal.is-open .af-modal__panel {
		transform: none;
	}

	.af-modal__body {
		padding: var(--af-space-lg);
	}
}

/* -------------------------------------------------------------------------
 * 2. Mini cart
 * ---------------------------------------------------------------------- */

.af-mini-cart {
	display: grid;
	gap: var(--af-space-md);
}

.af-mini-cart__item {
	display: grid;
	grid-template-columns: 72px minmax(0, 1fr);
	gap: var(--af-space-sm);
	padding-bottom: var(--af-space-md);
	border-bottom: 1px solid var(--af-border);
}

.af-mini-cart__media {
	display: block;
}

.af-mini-cart__image {
	width: 72px;
	height: 90px;
	border-radius: var(--af-radius-sm);
	object-fit: cover;
	background: var(--af-surface);
}

.af-mini-cart__body {
	min-width: 0;
}

.af-mini-cart__title {
	margin: 0;
	font-size: var(--af-fs-small);
	font-weight: 600;
}

.af-mini-cart__title a {
	color: inherit;
	text-decoration: none;
}

.af-mini-cart__meta,
.af-cart-item__brand {
	margin: 2px 0 0;
	color: var(--af-muted);
	font-size: var(--af-fs-caption);
}

.af-mini-cart__row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--af-space-sm);
	margin-top: var(--af-space-sm);
}

.af-mini-cart__price {
	font-family: var(--af-font-price);
	font-weight: 600;
}

.af-mini-cart__remove {
	padding: 0;
	border: 0;
	background: none;
	color: var(--af-muted);
	font-size: var(--af-fs-caption);
	text-decoration: underline;
}

.af-mini-cart__remove:hover {
	color: var(--af-error);
}

.af-mini-cart__cross-sells {
	padding-top: var(--af-space-md);
	border-top: 1px solid var(--af-border);
}

.af-mini-cart__footer {
	display: grid;
	gap: var(--af-space-sm);
}

.af-mini-cart__subtotal {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	font-weight: 600;
}

.af-mini-cart__subtotal-value {
	font-family: var(--af-font-price);
	font-size: var(--af-fs-h5);
}

.af-mini-cart__note {
	margin: 0;
	color: var(--af-muted);
	font-size: var(--af-fs-caption);
}

.af-mini-cart__actions {
	display: grid;
	gap: var(--af-space-xs);
}

/* -------------------------------------------------------------------------
 * 3. Free shipping progress
 * ---------------------------------------------------------------------- */

.af-shipping-bar {
	display: grid;
	gap: 6px;
	padding: var(--af-space-sm);
	border-radius: var(--af-radius-sm);
	background: var(--af-surface);
}

.af-shipping-bar__label {
	font-size: var(--af-fs-caption);
}

.af-shipping-bar__progress {
	height: 6px;
	border-radius: 999px;
	background: var(--af-border);
	overflow: hidden;
}

.af-shipping-bar__progress > span,
.af-shipping-progress {
	display: block;
	height: 100%;
	border-radius: inherit;
	background: var(--af-success);
	transition: width 0.4s ease;
}

/* -------------------------------------------------------------------------
 * 4. Quick view
 * ---------------------------------------------------------------------- */

.af-quick-view {
	display: grid;
	gap: var(--af-space-xl);
}

@media (min-width: 782px) {
	.af-quick-view {
		grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
	}
}

.af-quick-view__media,
.af-quick-view__gallery {
	min-width: 0;
}

.af-quick-view__stage img,
.af-quick-view__image {
	width: 100%;
	border-radius: var(--af-radius-image);
	background: var(--af-surface);
	aspect-ratio: 3 / 4;
	object-fit: cover;
}

.af-quick-view__thumbs {
	display: flex;
	gap: var(--af-space-xs);
	margin: var(--af-space-sm) 0 0;
	padding: 0;
	list-style: none;
	overflow-x: auto;
}

.af-quick-view__thumb {
	flex: none;
	width: 60px;
	padding: 0;
	border: 1px solid transparent;
	border-radius: var(--af-radius-sm);
	background: none;
	overflow: hidden;
}

.af-quick-view__thumb.is-active,
.af-quick-view__thumb[aria-current="true"] {
	border-color: var(--af-primary);
}

.af-quick-view__thumb img {
	display: block;
	width: 100%;
	height: auto;
}

/*
 * The form is WooCommerce's own add-to-cart template, so it arrives with the
 * plugin's markup. Only spacing is set here; the controls themselves inherit
 * the single product rules.
 */
.af-quick-view__form .quantity {
	margin-inline-end: var(--af-space-sm);
}

.af-quick-view__form form.cart {
	display: flex;
	flex-wrap: wrap;
	gap: var(--af-space-sm);
	align-items: center;
	margin: 0;
}

.af-quick-view__form form.variations_form {
	display: block;
}

.af-quick-view__form .button {
	flex: 1 1 180px;
}

.af-quick-view__summary {
	display: flex;
	flex-direction: column;
	gap: var(--af-space-sm);
	min-width: 0;
}

.af-quick-view__brand {
	margin: 0;
	color: var(--af-muted);
	font-size: var(--af-fs-caption);
	letter-spacing: 0.1em;
	text-transform: uppercase;
}

.af-quick-view__title {
	margin: 0;
	font-size: var(--af-fs-h3);
}

.af-quick-view__price {
	font-family: var(--af-font-price);
	font-size: var(--af-fs-h4);
	font-weight: 700;
}

.af-quick-view__excerpt {
	color: var(--af-secondary);
	font-size: var(--af-fs-small);
}

.af-quick-view__actions {
	display: flex;
	flex-wrap: wrap;
	gap: var(--af-space-sm);
	align-items: center;
}

.af-quick-view__full {
	color: var(--af-accent);
	font-size: var(--af-fs-small);
	font-weight: 600;
}

/* -------------------------------------------------------------------------
 * 5. Mobile menu drawer
 * ---------------------------------------------------------------------- */

.af-mobile-menu .af-drawer__search {
	padding: var(--af-space-md);
	border-bottom: 1px solid var(--af-border);
}

.af-mobile-nav__list,
.af-mobile-nav .af-nav__list {
	display: block;
	margin: 0;
	padding: 0;
	list-style: none;
}

.af-mobile-nav .af-menu-link {
	padding-block: 12px;
	font-size: var(--af-fs-base);
}

.af-mobile-nav .af-menu-item {
	border-bottom: 1px solid var(--af-border);
}

/* -------------------------------------------------------------------------
 * 6. Bottom navigation
 * ---------------------------------------------------------------------- */

.af-bottom-nav {
	position: fixed;
	inset-block-end: 0;
	inset-inline: 0;
	z-index: 70;
	display: none;
	border-top: 1px solid var(--af-border);
	background: var(--af-background);
	padding-block-end: env(safe-area-inset-bottom);
}

@media (max-width: 781px) {
	.af-bottom-nav {
		display: grid;
		grid-auto-flow: column;
		grid-auto-columns: 1fr;
	}

	/* Keep the last row of content clear of the bar. */
	body:has(.af-bottom-nav) {
		padding-bottom: 60px;
	}
}

.af-bottom-nav__item {
	position: relative;
	display: grid;
	place-items: center;
	gap: 2px;
	min-height: 56px;
	color: var(--af-muted);
	font-size: 11px;
	text-decoration: none;
}

.af-bottom-nav__item[aria-current="page"],
.af-bottom-nav__item:hover {
	color: var(--af-primary);
}

.af-bottom-nav__icon {
	position: relative;
}

.af-bottom-nav__label {
	line-height: 1;
}

/* -------------------------------------------------------------------------
 * 7. Checkout steps, account header, order extras
 * ---------------------------------------------------------------------- */

.af-steps {
	min-width: 0;
}

.af-steps__list {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: var(--af-space-md);
	margin: 0 0 var(--af-space-xl);
	padding: 0;
	list-style: none;
}

.af-steps__item {
	display: flex;
	align-items: center;
	gap: var(--af-space-sm);
	color: var(--af-muted);
	font-size: var(--af-fs-small);
}

.af-steps__number {
	display: grid;
	place-items: center;
	width: 26px;
	height: 26px;
	border: 1px solid currentColor;
	border-radius: 50%;
	font-size: var(--af-fs-caption);
	font-weight: 700;
}

.af-steps__item--current {
	color: var(--af-primary);
	font-weight: 600;
}

.af-steps__item--done {
	color: var(--af-success);
}

.af-steps__label {
	white-space: nowrap;
}

.af-steps__item a {
	color: inherit;
	text-decoration: none;
}

.af-account-header {
	display: flex;
	align-items: center;
	gap: var(--af-space-md);
	margin-bottom: var(--af-space-lg);
}

.af-account-header__image,
.af-account-header__avatar img {
	border-radius: 50%;
}

.af-account-header__text {
	min-width: 0;
}

.af-account-header__greeting {
	margin: 0;
	font-size: var(--af-fs-h4);
}

.af-account-header__hint {
	margin: 0;
	color: var(--af-muted);
	font-size: var(--af-fs-small);
}

.af-order-extras {
	display: grid;
	gap: var(--af-space-xl);
	margin-block: var(--af-space-xl);
}

.af-order-extras__next {
	padding: var(--af-space-lg);
	border: 1px solid var(--af-border);
	border-radius: var(--af-radius-md);
	background: var(--af-surface);
}

.af-order-extras__title {
	margin-bottom: var(--af-space-sm);
	font-size: var(--af-fs-h4);
}

.af-order-extras__steps {
	display: grid;
	gap: var(--af-space-sm);
	margin: 0;
	padding-inline-start: var(--af-space-lg);
	color: var(--af-secondary);
}

/* -------------------------------------------------------------------------
 * 8. Recently viewed and wishlist placeholders
 * ---------------------------------------------------------------------- */

.af-recently-viewed[hidden],
.af-wishlist-list[hidden],
.af-wishlist__client[hidden] {
	display: none;
}

.af-wishlist-page {
	padding-block-end: var(--af-space-xxl);
}

.af-wishlist {
	min-width: 0;
}

.af-recently-viewed-target:empty {
	min-height: 0;
}
