
/* =========================================================================
 * Mobile refinements — MarkGallery
 *
 * Most shoppers arrive on a phone, so this file tunes the parent theme for
 * small screens. Everything here is inside a max-width media query, so it
 * cannot affect the desktop layout.
 *
 * Two real problems it fixes:
 *   1. Product titles/prices dropped to 12–12.5px (and 10px on related
 *      products), which is hard to read and easy to mis-tap on a phone.
 *   2. The price and the "انتخاب گزینه‌ها" button sat cramped on one line.
 * ========================================================================= */

/* -------------------------------------------------------------------------
 * Product cards on phones
 * ---------------------------------------------------------------------- */
@media (max-width: 767px) {

	/* One card per row on the catalogue archives.
	 *
	 * Two up, the Persian name and the price were squeezed into a third of the
	 * screen each and the photo came out smaller than the things around it. A
	 * full-width card reads like a shop window instead of a table of thumbnails.
	 *
	 * Scoped to the two archive pages on purpose: the home "Selects" strip and
	 * the related-products row keep the layouts they were designed for. */
	body.mg-cat-archive ul.products,
	body.post-type-archive-product ul.products {
		grid-template-columns: 1fr;
	}

	/* Readable product title: allow two lines instead of truncating to one,
	 * so long Persian names are not cut off with an ellipsis. */
	.woocommerce ul.products li.product .woocommerce-loop-product__title,
	.woocommerce-page ul.products li.product .woocommerce-loop-product__title,
	.latest .woocommerce ul.products li.product .woocommerce-loop-product__title,
	.woocommerce.style-products ul.products li.product .woocommerce-loop-product__title {
		font-size: 14px;
		line-height: 1.7;
		white-space: normal;
		overflow: visible;
		text-overflow: clip;
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		overflow: hidden;
		margin-bottom: 6px;
	}

	.woocommerce ul.products li.product .price,
	.woocommerce-page ul.products li.product .price,
	.latest .woocommerce ul.products li.product .price,
	.woocommerce.style-products ul.products li.product .price {
		font-size: 14px;
		margin-bottom: 10px;
	}

	/* Full-width tap target with a comfortable height (>=44px). */
	.woocommerce ul.products li.product .button,
	.woocommerce-page ul.products li.product .button,
	.latest .woocommerce ul.products li.product .button,
	.woocommerce.style-products ul.products li.product .button {
		display: block;
		width: 100%;
		font-size: 13px;
		padding: 12px 8px;
		line-height: 1.5;
	}

	/* Related products on the product page were at 10px.
	 *
	 * No `overflow` here on purpose. This rule used to set `overflow: visible`,
	 * which silently switched off the two-line clamp the shared card rule relies
	 * on (`-webkit-line-clamp` only clips when the box clips): a long name such as
	 * «کاپشن چرم مشکی Bamber Jacket» spilled a third line straight over the price
	 * underneath. The name keeps the site-wide two-line cap, only smaller. */
	.single-product .related.products ul.products li.product .woocommerce-loop-product__title {
		font-size: 13px;
		white-space: normal;
		text-overflow: clip;
	}
	.single-product .related.products ul.products li.product .price {
		font-size: 13px;
	}
}

/* -------------------------------------------------------------------------
 * Very small phones: keep two product columns readable rather than shrinking
 * further. Below 360px a single column reads much better.
 * ---------------------------------------------------------------------- */
@media (max-width: 359px) {
	.woocommerce ul.products,
	.woocommerce-page ul.products {
		grid-template-columns: 1fr !important;
	}
}

/* -------------------------------------------------------------------------
 * Touch targets elsewhere on the site
 * ---------------------------------------------------------------------- */
@media (max-width: 767px) {

	/* Quantity steppers and small icon buttons need a real tap area. */
	.woocommerce .quantity input.qty,
	.summary .brand-q input.qty {
		min-height: 44px;
		font-size: 16px; /* 16px stops iOS from zooming the page on focus */
	}

	.woocommerce form .form-row input.input-text,
	.woocommerce form .form-row textarea,
	.woocommerce form .form-row select,
	.select2-container--default .select2-selection--single {
		min-height: 44px;
		font-size: 16px;
	}

	/* Pagination links are tiny by default. */
	.woocommerce nav.woocommerce-pagination ul li a,
	.woocommerce nav.woocommerce-pagination ul li span {
		min-width: 44px;
		min-height: 44px;
		line-height: 44px;
		display: inline-block;
	}
}

/* -------------------------------------------------------------------------
 * One card anatomy across a row
 *
 * Measured at 390px on the homepage grid: two cards in the same row, one with a
 * two-line title and one with a single line, put their «انتخاب گزینه‌ها»
 * buttons 24px apart. The cards themselves are already the same height — the
 * grid stretches them — but the contents flow from the top, so a wrapped title
 * pushes its own price and button down while its neighbour's stay up. The row
 * reads as broken even though each card is individually fine.
 *
 * Making the card a column and giving the price `margin-top:auto` pins the
 * price + button pair to the bottom edge of every card, so they share one
 * baseline in the row no matter how many lines a name needs. This is the
 * standard card anatomy for exactly this reason and it needs no fixed heights
 * and no JavaScript.
 *
 * Applies to every loop on the site (shop, category, homepage, related), which
 * is where the defect was visible.
 * ---------------------------------------------------------------------- */
@media (max-width: 767px) {

	.woocommerce ul.products li.product,
	.woocommerce-page ul.products li.product {
		display: flex;
		flex-direction: column;
	}

	/* The card's own link wraps the image, the name AND the price — only the
	 * button sits outside it. So the price can only be pinned to the bottom if
	 * the link itself is the flex column that fills the card. Without this the
	 * `margin-top:auto` below has no flex parent to push against and does
	 * nothing (measured: the 24px gap did not move). */
	.woocommerce ul.products li.product > a.woocommerce-LoopProduct-link,
	.woocommerce-page ul.products li.product > a.woocommerce-LoopProduct-link {
		display: flex;
		flex-direction: column;
		flex: 1 1 auto;
	}

	.woocommerce ul.products li.product > a.woocommerce-LoopProduct-link .price,
	.woocommerce-page ul.products li.product > a.woocommerce-LoopProduct-link .price {
		margin-top: auto;
	}

	/* The «Mark Gallery Selects» cards are a different component: a single
	 * absolutely-positioned overlay whose title and price are pinned to its own
	 * corners. Column flow would fight that, so they keep their own layout. */
	.picks .woocommerce ul.products li.product,
	.picks .woocommerce ul.products li.product > a.woocommerce-LoopProduct-link {
		display: block;
	}
}

/* -------------------------------------------------------------------------
 * Footer links: three even rows instead of 4 + 2
 *
 * The footer is built from three groups of two links each, and from 900px down
 * the parent theme lays `.fgrid` out in two columns. Three groups cannot fill
 * two columns, so the third group wrapped onto its own row and both of its
 * links stayed in the right column: four links on the right, two on the left,
 * and «ارتباط با ما» ended up underneath «درباره ما» instead of facing it.
 *
 * Flattening the two wrappers lets the six links lay themselves out as three
 * balanced rows, and because the groups are in pairs each row keeps its
 * original pairing:
 *
 *     آدرس        | ژورنال مارک گالری
 *     باشگاه مشتریان | سوالات متداول
 *     درباره ما    | ارتباط با ما
 *
 * `display: contents` is used deliberately: it removes only the wrapper boxes,
 * so no markup and no menu order changes. It costs the `<ul>` its list role in
 * some screen readers, which is acceptable here — the links themselves are
 * still links, and the footer is a set of destinations rather than a data list.
 * ---------------------------------------------------------------------- */
@media (max-width: 767px) {

	.fgrid > div,
	.fgrid > div > ul {
		display: contents;
	}

	.fgrid li {
		list-style: none;
		margin: 0;
	}

	/* Exchange «باشگاه مشتریان» and «ارتباط با ما».
	 *
	 * Only these two links move; every other cell keeps the position the flow
	 * above gives it, so the rows stay balanced:
	 *
	 *     آدرس          | ژورنال مارک گالری
	 *     ارتباط با ما   | سوالات متداول
	 *     درباره ما      | باشگاه مشتریان
	 *
	 * They are matched by destination rather than by position, so reordering
	 * the WordPress menu later cannot silently swap the wrong pair — and the
	 * two support links now share a row while the two "about" links do too.
	 *
	 * `:has()` is used because the grid item is the `<li>` while the only
	 * stable identifier is its link. Where `:has()` is unsupported the rule is
	 * simply ignored, which leaves the previous balanced layout intact rather
	 * than breaking it. */
	.fgrid li:has(> a[href$="/customer-club/"]) {
		grid-column: 2;
		grid-row: 3;
	}

	.fgrid li:has(> a[href$="/contact-us/"]) {
		grid-column: 1;
		grid-row: 2;
	}
}

/* -------------------------------------------------------------------------
 * Navigation drawer: a panel, not a sheet
 *
 * The parent theme's mobile block sizes the drawer with
 * `width:min(86vw,300px)`. Because of that 300px ceiling, the percentage only
 * decided the outcome below 349px — on every phone wider than that the drawer
 * was a flat 300px, and the dimmed strip a shopper can see and tap shrank to
 * almost nothing:
 *
 *     320px  →  275px  (86.0% drawer, 45px strip)
 *     360px  →  300px  (83.3%, 60px)
 *     390px  →  300px  (76.9%, 90px)
 *     430px  →  300px  (69.8%, 130px)
 *
 * Two things this rule has to respect, both measured rather than assumed:
 *
 *   - The drawer cannot get narrower than 224px. The search field loses 48px to
 *     the drawer's own padding and 52px to the close button's reserve, so a
 *     224px drawer leaves an 82px input — and the «جستجو کنید...» placeholder
 *     is 77px in the theme's own font. At 218px it clips. That is the floor.
 *   - The top-level labels are all short (the longest, «پیراهن مردانه», is
 *     79px), so they never bound the width; the search field does.
 *
 * `clamp()` therefore states the real requirement in one line: 68vw as the
 * intent, 268px as the ceiling so wide phones narrow too (a 300px cap is what
 * silently cancelled the previous attempt on every 394px+ screen), and 224px
 * as the floor that keeps the placeholder intact on a 320px phone.
 *
 *     320px  →  224px  (70.0%, strip 96px)
 *     360px  →  245px  (68.0%, strip 115px)
 *     390px  →  265px  (68.0%, strip 125px)
 *     430px  →  268px  (62.3%, strip 162px)
 *
 * Mobile tier only. The tablet range (768–1023) keeps the parent's 260px and
 * desktop is untouched, both by being outside this media query.
 * ---------------------------------------------------------------------- */
@media (max-width: 767px) {
	.panel {
		width: clamp(224px, 68vw, 268px);
	}
}

/* -------------------------------------------------------------------------
 * Archive product grid: put a gutter back on the page edge
 *
 * The WooCommerce archive loop is a body-level element on this site — measured
 * on the «بافت» category: `<ul class="products">` has `<body>` as its parent,
 * sits at left 0, and is 390px wide on a 390px phone (1280 of 1280 on desktop).
 * Nothing in the theme wraps it, so the outer cards touch the screen edge.
 *
 * The selector is deliberately `body.woocommerce > ul.products`: only the loop
 * that really has no wrapper is inset. Every other loop on the site (the home
 * page's latest products, the SELECTS band, related products) already sits
 * inside a container with its own gutter, and a broader rule double-inset them
 * — measured: the home page's cards shrank from 176px to 162px a side.
 *
 * 14px is the value `.wrap` already uses for its own padding at this width
 * (main.css:381), so the cards line up with the rest of the page instead of
 * inventing a second rhythm. Padding, not margin: the list keeps its full width
 * and `repeat(2,1fr)` yields two 176px columns inside it (390 − 28 − 10 gap).
 * The two element names in the selector are what beat main.css:148's
 * `.woocommerce ul.products` on specificity without an !important.
 * ---------------------------------------------------------------------- */
@media (max-width: 767px) {
	body.woocommerce > ul.products {
		padding-left: 14px;
		padding-right: 14px;
	}
}
