/**
 * FlexiDesignX — Mobile Styles
 *
 * Mobile tab bar, touch-friendly adjustments, sticky PDP cart bar.
 *
 * Specificity strategy: use `body` prefix or doubled selectors to beat
 * parent-theme (Funori) specificity instead of !important.
 * Remaining !important kept ONLY where truly unavoidable (e.g. hiding
 * elements that Funori forces visible with its own !important).
 *
 * @package FlexiDesignX
 * @since   1.0.0
 */

/* ==========================================================================
   Mobile Bottom Tab Bar
   ========================================================================== */

.fdx-mobile-tab-bar {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	height: var(--fdx-mobile-tab-bar-height);
	background-color: var(--fdx-white);
	border-top: 1px solid var(--fdx-grey-200);
	display: flex;
	align-items: center;
	justify-content: space-around;
	z-index: 999;
	box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
	padding-bottom: env(safe-area-inset-bottom, 0);
}

.fdx-mobile-tab-bar__item {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	flex: 1;
	padding: var(--fdx-space-xs) 0;
	color: var(--fdx-grey-500);
	text-decoration: none;
	position: relative;
	-webkit-tap-highlight-color: transparent;
	transition: color 0.2s ease;
}

.fdx-mobile-tab-bar__item--active {
	color: var(--fdx-accent);
}

.fdx-mobile-tab-bar__icon {
	font-size: 1.25rem;
	line-height: 1;
}

.fdx-mobile-tab-bar__label {
	font-size: var(--fdx-font-size-xs);
	margin-top: 2px;
}

.fdx-mobile-tab-bar__badge {
	position: absolute;
	top: 0;
	right: 50%;
	transform: translateX(12px);
	background-color: var(--fdx-gold);
	color: var(--fdx-accent);
	font-size: 10px;
	font-weight: 700;
	min-width: 16px;
	height: 16px;
	border-radius: var(--fdx-radius-full);
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0 4px;
}

/* Add bottom padding to body for tab bar */
body {
	padding-bottom: var(--fdx-mobile-tab-bar-height);
}

/* ==========================================================================
   Sticky Add to Cart Bar — PDP Mobile (Shopee-style)
   ========================================================================== */

.fdx-sticky-cart {
	position: fixed;
	bottom: var(--fdx-mobile-tab-bar-height);
	left: 0;
	right: 0;
	background: var(--fdx-white);
	border-top: 1px solid var(--fdx-grey-200);
	box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.08);
	z-index: 998;
	display: none;
	padding: 0.5rem 1rem;
	padding-bottom: calc(0.5rem + env(safe-area-inset-bottom, 0));
}

.fdx-sticky-cart--visible {
	display: flex;
	gap: 0;
	align-items: center;
}

.fdx-sticky-cart__chat {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 0.5rem 0.75rem;
	color: var(--fdx-accent);
	text-decoration: none;
	font-size: 0.625rem;
	font-weight: 500;
	flex-shrink: 0;
	border-right: 1px solid var(--fdx-grey-200);
}

.fdx-sticky-cart__chat-icon {
	font-size: 1.25rem;
	margin-bottom: 0.125rem;
}

.fdx-sticky-cart__atc {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 0.375rem;
	padding: 0.625rem;
	background: var(--fdx-accent-light);
	color: var(--fdx-accent);
	border: 1px solid var(--fdx-accent);
	border-right: none;
	font-size: var(--fdx-font-size-sm);
	font-weight: 600;
	cursor: pointer;
}

.fdx-sticky-cart__buy {
	flex: 1;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 0.625rem;
	background: var(--fdx-accent);
	color: var(--fdx-white);
	border: 1px solid var(--fdx-accent);
	font-size: var(--fdx-font-size-sm);
	font-weight: 600;
	text-decoration: none;
	cursor: pointer;
}

.fdx-sticky-cart__buy:hover {
	color: var(--fdx-white);
}

/* Adjust body padding on single product pages with sticky bar */
.single-product body {
	padding-bottom: calc(var(--fdx-mobile-tab-bar-height) + 52px);
}

/* ==========================================================================
   Mobile Header Adjustments
   ========================================================================== */

@media (max-width: 767px) {
	/* Mobile header */
	body .fdx-header__logo-text {
		font-size: 1.125rem;
	}

	body .fdx-header__logo-img {
		max-height: 26px;
		padding: 3px 6px;
	}

	body .fdx-header__inner {
		gap: 0.4rem;
		padding-top: 0.5rem;
		padding-bottom: 0.5rem;
	}

	body .fdx-header__icons {
		gap: 0.15rem;
	}

	body .fdx-header__icon {
		min-width: 44px;
		min-height: 44px;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 0.25rem;
	}

	/* Touch-friendly topbar links */
	body .fdx-topbar__links a {
		min-height: 44px;
		display: inline-flex;
		align-items: center;
		padding: 0.5rem 0.75rem;
	}

	/* Touch-friendly section links */
	body .fdx-section__link {
		min-height: 44px;
		display: inline-flex;
		align-items: center;
		padding: 0.625rem 1rem;
	}

	body .fdx-header__icon svg {
		width: 18px;
		height: 18px;
	}

	/* Hide header search on mobile — bottom tab "Search" replaces it */
	body .fdx-header__search {
		display: none;
	}

	body .fdx-header__logo-img {
		max-height: 30px;
		padding: 3px 8px;
	}

	body .fdx-header__inner {
		justify-content: space-between;
	}

	body .fdx-header__icon svg {
		width: 20px;
		height: 20px;
	}

	/* Keep hero search visible on mobile as primary search */
	body .fdx-hero__search {
		display: block;
	}

	/* Hide nav bar on mobile — tab bar replaces it */
	body .fdx-nav {
		display: none;
	}

	/* ---- Footer only on homepage mobile ---- */
	body .fdx-footer { display: none; }
	body.home .fdx-footer { display: block; }

	/* ---- PDP mobile — Shopee full-screen style ---- */
	/* Hide header/topbar on PDP — use high specificity to beat Funori */
	body.single-product .fdx-topbar,
	body.single-product .fdx-header,
	body.single-product .fdx-nav { display: none; }

	/* Hide tab bar on PDP — sticky cart replaces it */
	body.single-product .fdx-mobile-tab-bar { display: none; }
	body.single-product { padding-bottom: 0; }

	/* Full-width gallery on PDP */
	body.single-product .fdx-pdp__gallery {
		margin: 0 -1rem;
	}
	body.single-product .fdx-pdp__main-image {
		border-radius: 0;
		aspect-ratio: 1/1;
	}
	body.single-product .fdx-pdp__main-image img {
		width: 100%;
		height: 100%;
		object-fit: cover;
	}

	/* Thumbnails as horizontal scroll strip */
	body.single-product .fdx-pdp__thumbnails {
		display: flex;
		gap: 6px;
		padding: 8px 12px;
		overflow-x: auto;
		-webkit-overflow-scrolling: touch;
		scrollbar-width: none;
	}
	body.single-product .fdx-pdp__thumbnails::-webkit-scrollbar { display: none; }
	body.single-product .fdx-pdp__thumb {
		flex-shrink: 0;
		width: 56px;
		height: 56px;
		border-radius: 6px;
	}

	/* Hide breadcrumb on PDP mobile */
	body.single-product .fdx-breadcrumb { display: none; }

	/* Floating back + cart overlay on product image */
	.fdx-pdp-mobile-nav {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 100;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 10px 12px;
		padding-top: calc(10px + env(safe-area-inset-top, 0));
		background: linear-gradient(180deg, rgba(0,0,0,0.25) 0%, transparent 100%);
		pointer-events: none;
	}
	.fdx-pdp-mobile-nav__back,
	.fdx-pdp-mobile-nav__cart {
		pointer-events: auto;
		width: 44px;
		height: 44px;
		border-radius: 50%;
		background: rgba(0,0,0,0.35);
		color: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
		text-decoration: none;
		backdrop-filter: blur(4px);
		position: relative;
	}
	.fdx-pdp-mobile-nav__badge {
		position: absolute;
		top: -4px;
		right: -4px;
		background: var(--fdx-accent);
		color: #fff;
		font-size: 0.6rem;
		font-weight: 800;
		min-width: 16px;
		height: 16px;
		border-radius: 8px;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 0 4px;
	}

	/* PDP sticky bottom bar — Add to Cart + Buy Now only, equal size */
	body.single-product .fdx-sticky-cart {
		bottom: 0;
		border-radius: 0;
		border-top: 1px solid #f0ece9;
	}
	body.single-product .fdx-sticky-cart--visible {
		display: flex;
		gap: 0;
		padding: 0;
		padding-bottom: env(safe-area-inset-bottom, 0);
	}
	/* Hide Chat button */
	body.single-product .fdx-sticky-cart__chat { display: none; }
	/* Equal width buttons */
	body.single-product .fdx-sticky-cart__atc,
	body.single-product .fdx-sticky-cart__buy {
		flex: 1 1 50%;
		width: 50%;
		font-size: 0.95rem;
		font-weight: 700;
		border-radius: 0;
		padding: 14px 8px;
		border: none;
		text-align: center;
		justify-content: center;
		box-sizing: border-box;
	}
	body.single-product .fdx-sticky-cart__atc {
		background: var(--fdx-accent-light);
		color: var(--fdx-accent);
		border-right: 1px solid #e5e0dc;
	}
	body.single-product .fdx-sticky-cart__buy {
		background: var(--fdx-accent);
		color: #fff;
	}

	body .fdx-nav__menu li a {
		padding: 0.5rem 0.75rem;
		font-size: var(--fdx-font-size-xs);
	}

	/* PDP: stack gallery above info — high specificity to beat Storefront */
	body main.fdx-single-product .fdx-pdp {
		flex-direction: column;
	}

	body main.fdx-single-product .fdx-pdp__gallery {
		flex: none;
		width: 100%;
		max-width: 100%;
	}

	body main.fdx-single-product .fdx-pdp__info {
		padding: 1rem;
	}

	/* Quantity buttons: 44px touch targets */
	body .fdx-pdp__qty-btn {
		width: 44px;
		height: 44px;
		font-size: 1.25rem;
	}

	body .fdx-pdp__qty-input {
		height: 44px;
		width: 56px;
	}

	/* Hide main action buttons on mobile — sticky bar takes over */
	body.single-product .fdx-pdp__actions {
		display: none;
	}

	/* Related products: 2 columns */
	body .fdx-product-grid--related {
		grid-template-columns: repeat(2, 1fr);
	}
}

/* ==========================================================================
   Desktop — hide mobile elements
   ========================================================================== */

@media (min-width: 768px) {
	.fdx-mobile-tab-bar {
		display: none;
	}

	body {
		padding-bottom: 0;
	}
}

@media (min-width: 1025px) {
	.fdx-sticky-cart {
		display: none;
	}

	.fdx-pdp-mobile-nav {
		display: none;
	}
}

/* ==========================================================================
   Mobile fixes — v2.0
   ========================================================================== */

@media (max-width: 767px) {
	/* WhatsApp button: move above tab bar and don't overlap sticky cart */
	body .fdx-whatsapp-btn {
		bottom: calc(var(--fdx-mobile-tab-bar-height) + 12px);
		right: 12px;
		z-index: 997;
	}
	body.single-product .fdx-whatsapp-btn {
		bottom: calc(var(--fdx-mobile-tab-bar-height) + 60px);
	}

	/* PDP sticky bar: ensure Buy Now text doesn't clip */
	body .fdx-sticky-cart__buy {
		font-size: 0.8rem;
		white-space: nowrap;
		padding: 0.625rem 0.75rem;
	}
	body .fdx-sticky-cart__atc {
		font-size: 0.8rem;
	}

	/* ==============================================
	   Cart mobile — Shopee card layout
	   ============================================== */
	body.woocommerce-cart .woocommerce-cart-page.row {
		grid-template-columns: 1fr;
	}

	/* ==============================================
	   Cart mobile — Exact Shopee layout
	   Funori DOM: td.product-thumbnail has image+name link,
	   then td.product-price, td.product-quantity, td.product-subtotal, td.product-remove
	   ============================================== */

	/* Grey page background like Shopee */
	body.woocommerce-cart .woocommerce { background: #f5f5f5; padding: 0.75rem; border-radius: 0; }

	/* Keep header/topbar visible on cart — only hide nav (tab bar replaces it) */
	body.woocommerce-cart .fdx-nav { display: none; }

	/* Hide step indicator — replace with simple title */
	body.woocommerce-cart .woocommerce-page-header { display: none; }

	/* Cart page title bar */
	body.woocommerce-cart .woocommerce::before {
		content: "Shopping Cart";
		display: block;
		text-align: center;
		font-size: 1.1rem;
		font-weight: 700;
		color: #222;
		padding: 14px 0 10px;
		background: #fff;
		margin: -0.75rem -0.75rem 0.75rem;
		border-bottom: 1px solid #f0ece9;
	}

	/* Sticky bottom checkout bar */
	body.woocommerce-cart .cart_totals {
		position: fixed;
		bottom: var(--fdx-mobile-tab-bar-height);
		left: 0; right: 0;
		z-index: 998;
		margin: 0;
		border-radius: 0;
		padding: 0;
		box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
		background: #fff;
	}
	body.woocommerce-cart .cart_totals h2 { display: none; }
	body.woocommerce-cart .cart_totals table {
		position: absolute; width: 1px; height: 1px;
		overflow: hidden; clip: rect(0,0,0,0); border: 0;
	}

	/* Show only total + checkout in sticky bar */
	body.woocommerce-cart .cart_totals::before {
		content: none; /* remove free delivery pseudo */
	}
	body.woocommerce-cart .cart_totals::after {
		content: none;
	}

	/* Custom sticky bar layout */
	body.woocommerce-cart .wc-proceed-to-checkout {
		display: flex;
		align-items: center;
		padding: 10px 12px;
		padding-bottom: calc(10px + env(safe-area-inset-bottom, 0));
		gap: 12px;
		margin: 0;
	}
	body.woocommerce-cart .wc-proceed-to-checkout::before {
		content: "Total";
		font-size: 0.82rem;
		color: #999;
		white-space: nowrap;
	}
	body.woocommerce-cart .wc-proceed-to-checkout::after {
		content: none;
	}

	body.woocommerce-cart .fdx-sticky-total {
		flex: 1;
		font-size: 1.15rem;
		font-weight: 800;
		color: var(--fdx-accent);
		text-align: right;
		padding-right: 8px;
	}
	body.woocommerce-cart .wc-proceed-to-checkout .checkout-button {
		flex-shrink: 0;
		width: auto;
		min-width: 140px;
		padding: 12px 24px;
		font-size: 0.95rem;
		border-radius: 8px;
		box-shadow: none;
	}

	/* Hide the free delivery / grabpay notes in sticky */
	body.woocommerce-cart .cart_totals > *:not(.wc-proceed-to-checkout) {
		display: none;
	}
	/* Ensure checkout link is visible in sticky bar.
	   Funori hides .wc-proceed-to-checkout in some contexts, so !important needed. */
	body.woocommerce-cart .cart_totals .wc-proceed-to-checkout {
		display: flex !important;
	}

	/* Adjust body padding for sticky bar */
	body.woocommerce-cart .woocommerce .cart-collaterals {
		padding-bottom: 80px;
	}

	/* Keep mobile tab bar visible on cart page for navigation */
	body.woocommerce-cart { padding-bottom: var(--fdx-mobile-tab-bar-height); }

	/* Kill table structure */
	body.woocommerce-cart table.shop_table thead { display: none; }
	body.woocommerce-cart table.shop_table {
		background: #fff;
		border-radius: 12px;
		box-shadow: none;
		border: none;
		overflow: hidden;
	}
	body.woocommerce-cart table.shop_table,
	body.woocommerce-cart table.shop_table tbody {
		display: block; border: none;
	}

	/* ---- Each item row ---- */
	body.woocommerce-cart table.shop_table tr.woocommerce-cart-form__cart-item {
		display: block;
		position: relative;
		padding: 12px;
		border: none;
		border-bottom: 1px solid #f0ece9;
	}
	body.woocommerce-cart table.shop_table tr.woocommerce-cart-form__cart-item td {
		display: block; width: auto; border: none; padding: 0;
	}

	/* Thumbnail+Name: flex row, image left, name right */
	body.woocommerce-cart table.shop_table .product-thumbnail {
		display: flex;
		gap: 10px;
		align-items: flex-start;
		width: 100%;
	}
	body.woocommerce-cart table.shop_table .product-thumbnail a:first-child {
		flex-shrink: 0;
	}
	body.woocommerce-cart table.shop_table .product-thumbnail img {
		width: 100px;
		height: 100px;
		border-radius: 8px;
		object-fit: cover;
		border: 1px solid #eee;
	}
	/* Name link — takes remaining width */
	body.woocommerce-cart table.shop_table .product-thumbnail a:last-child {
		flex: 1;
		min-width: 0;
		font-size: 0.88rem;
		font-weight: 500;
		line-height: 1.4;
		color: #222;
		text-decoration: none;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		overflow: hidden;
	}

	/* Price + Qty row: sits below the thumbnail row */
	body.woocommerce-cart table.shop_table .product-price {
		margin-top: 8px;
		margin-left: 110px; /* 100px image + 10px gap */
		font-size: 1rem;
		font-weight: 700;
		color: var(--fdx-accent);
		display: inline-block;
	}

	body.woocommerce-cart table.shop_table .product-quantity {
		position: absolute;
		right: 12px;
		bottom: 12px;
	}
	body.woocommerce-cart table.shop_table .quantity {
		border: 1px solid #e0e0e0;
		border-radius: 4px;
		display: inline-flex;
		align-items: center;
	}
	body.woocommerce-cart table.shop_table .quantity .minus,
	body.woocommerce-cart table.shop_table .quantity .plus {
		width: 44px; height: 44px;
		background: #fafafa;
		border: none;
		font-size: 0.9rem;
		color: #555;
		display: flex; align-items: center; justify-content: center;
		cursor: pointer;
	}
	body.woocommerce-cart table.shop_table .quantity .qty {
		width: 32px; height: 44px;
		border: none;
		border-left: 1px solid #e0e0e0;
		border-right: 1px solid #e0e0e0;
		text-align: center;
		font-size: 0.85rem;
		font-weight: 600;
		padding: 0;
		-moz-appearance: textfield;
	}
	body.woocommerce-cart table.shop_table .quantity .qty::-webkit-inner-spin-button { -webkit-appearance: none; }

	/* Hide subtotal + remove (Shopee uses swipe-to-delete) */
	body.woocommerce-cart table.shop_table .product-subtotal { display: none; }
	body.woocommerce-cart table.shop_table .product-remove { display: none; }
	/* Quantity cell also has a hidden label with product name — hide overflow */
	body.woocommerce-cart table.shop_table .product-quantity label { display: none; }

	/* ---- Coupon / Actions ---- */
	body.woocommerce-cart table.shop_table tr td.actions {
		display: block;
		width: 100%;
		padding: 12px;
		background: #fff;
		border-top: 1px solid #f0ece9;
	}
	body.woocommerce-cart table.shop_table td.actions .coupon {
		display: flex; gap: 8px;
	}
	body.woocommerce-cart table.shop_table td.actions .coupon input {
		flex: 1; font-size: 0.85rem; max-width: none;
		border: 1px solid #e0e0e0; border-radius: 8px; padding: 8px 12px;
	}
	body.woocommerce-cart table.shop_table td.actions .coupon .button {
		border-radius: 8px; padding: 8px 16px; font-size: 0.85rem;
	}
	body.woocommerce-cart table.shop_table td.actions > a { display: none; }
	/* Hide "Continue Shopping" heading (Funori wraps it in h2) */
	body.woocommerce-cart h2 > a[href*="shop"],
	body.woocommerce-cart a[href*="shop"]:not(.checkout-button):not(.fdx-header__logo):not([class]) {
		display: none;
	}
	body.woocommerce-cart .woocommerce-cart-form h2 { display: none; }
	body.woocommerce-cart table.shop_table td.actions button[name="update_cart"] {
		width: 100%; margin-top: 8px; font-size: 0.85rem;
		padding: 8px; border-radius: 8px;
	}

	/* ---- Cart totals card ---- */
	body.woocommerce .cart-collaterals { margin-top: 10px; }
	body.woocommerce .cart_totals {
		background: #fff;
		border-radius: 12px;
		padding: 16px;
		margin-bottom: calc(var(--fdx-mobile-tab-bar-height) + 12px);
	}
	body.woocommerce .cart_totals h2 { font-size: 1rem; margin-bottom: 12px; }
	body.woocommerce .wc-proceed-to-checkout .checkout-button {
		font-size: 1rem; padding: 14px; border-radius: 10px;
	}

	/* Step indicator single line */
	body .woocommerce-page-header { margin-bottom: 10px; padding-bottom: 8px; }
	body .woocommerce-page-header ul { font-size: 0.82rem; flex-wrap: nowrap; }
	body .woocommerce-page-header li { white-space: nowrap; }

	/* Hide WhatsApp on cart */
	body.woocommerce-cart .fdx-whatsapp-btn { display: none; }

	/* Checkout mobile: single column */
	body.woocommerce-checkout form.checkout > .row {
		grid-template-columns: 1fr;
	}
	body.woocommerce-checkout .col-xl-4 {
		position: static;
	}

	/* My Account mobile: stack */
	body.woocommerce-account .woocommerce {
		grid-template-columns: 1fr;
	}

	/* ==============================================
	   Small mobile (375px) — less cramped product cards
	   ============================================== */
	@media (max-width: 400px) {
		.fdx-product-grid {
			grid-template-columns: repeat(2, 1fr);
			gap: 8px;
		}
		.fdx-product-card__info {
			padding: 8px;
		}
		.fdx-product-card__title {
			font-size: 0.75rem;
			-webkit-line-clamp: 2;
		}
		.fdx-product-card__price {
			font-size: 0.8rem;
		}
		.fdx-grabpay {
			font-size: 0.65rem;
		}
		.fdx-grabpay__logo {
			height: 12px;
		}
	}

	/* Shop sidebar on mobile: compact horizontal scrolling pills */
	body .fdx-sidebar {
		padding: 0.5rem 0.75rem;
		overflow: hidden;
	}
	body .fdx-sidebar__title { font-size: 0.85rem; margin-bottom: 0.4rem; }
	body .fdx-sidebar__filter { display: none; } /* Hide price filter on mobile */
	body .fdx-sidebar__categories {
		display: flex;
		flex-wrap: nowrap;
		gap: 0.4rem;
		overflow-x: auto;
		-webkit-overflow-scrolling: touch;
		scrollbar-width: none;
	}
	body .fdx-sidebar__categories::-webkit-scrollbar {
		display: none;
	}
	body .fdx-sidebar__categories li {
		flex-shrink: 0;
	}
	body .fdx-sidebar__categories li a {
		display: inline-block;
		padding: 0.4rem 0.8rem;
		background: #fff;
		border: 1px solid #e5e0dc;
		border-radius: 20px;
		font-size: 0.78rem;
		white-space: nowrap;
	}
	body .fdx-sidebar__categories li.current-cat a {
		background: var(--fdx-accent);
		color: #fff;
		border-color: var(--fdx-accent);
	}
}
