/**
 * AgriHarvest — Dedicated responsive layer (tablet & mobile)
 *
 * Load order: after main.css, so equal-specificity rules win.
 *
 * Breakpoint strategy:
 *   1080px — navigation switches to mobile drawer (safely before tablets)
 *    992px — single-column layouts, 2-col grids
 *    768px — tablet portrait fine-tuning
 *    640px — large phones: 1-col grids, stacked tables
 *    480px — small phones
 *   hover:none — touch devices (no hover-dependent UI)
 *   landscape  — short-height tuning
 *
 * @package AgriHarvest
 */

/* ==========================================================================
   0. Foundations: no horizontal scroll, iOS text size, tap highlight
   ========================================================================== */
html {
	overflow-x: hidden;
	-webkit-text-size-adjust: 100%;
	text-size-adjust: 100%;
}
body { overflow-x: hidden; }

a, button, .btn, .filter-chip, .dot, .menu-toggle, .search-toggle, .header-cart {
	-webkit-tap-highlight-color: transparent;
}

/* Smooth anchor targets below the sticky header */
section[id], div[id] { scroll-margin-top: 96px; }

/* Entry-content tables: horizontally scrollable instead of breaking layout */
.entry-content table,
.wp-block-table table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.wp-block-table td, .wp-block-table th { min-width: 90px; }

/* Notched devices (iPhone X+): respect safe areas */
.top-bar { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.main-header { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.site-footer { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.back-to-top { right: calc(26px + env(safe-area-inset-right)); bottom: calc(26px + env(safe-area-inset-bottom)); }

/* Menu-open scroll lock (applied by JS on phones/tablets) */
body.agri-menu-open { overflow: hidden; }

/* ==========================================================================
   1. ≤1080px — Navigation becomes the mobile drawer (covers tablets)
   ========================================================================== */
@media (max-width: 1080px) {
	.menu-toggle { display: inline-flex; }
	.main-navigation { order: 3; }

	.primary-menu {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: auto;
		width: min(360px, 88vw);
		height: 100%;
		height: 100dvh; /* dynamic viewport for mobile Safari URL bar */
		background: var(--agri-white);
		flex-direction: column;
		align-items: stretch;
		gap: 0;
		padding: 76px 22px 32px;
		box-shadow: -12px 0 40px rgba(23, 41, 28, 0.18);
		display: flex;
		overflow-y: auto;
		-webkit-overflow-scrolling: touch;
		overscroll-behavior: contain;
		transform: translateX(105%);
		transition: transform 0.32s ease;
		z-index: 999;
	}
	.main-navigation.toggled .primary-menu { transform: translateX(0); }
	.main-navigation.toggled::before {
		content: "";
		position: fixed;
		inset: 0;
		background: rgba(22, 48, 31, 0.55);
		backdrop-filter: blur(2px);
		z-index: 998;
	}

	/* Menu items = comfortable 48px+ rows with visible separators */
	.primary-menu > li { border-bottom: 1px solid var(--agri-border); }
	.primary-menu > li > a {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 15px 6px;
		font-size: 1.02rem;
		border-radius: 0;
	}
	.primary-menu > li > a:hover { background: transparent; color: var(--agri-primary); }
	.primary-menu > li.menu-item-has-children::after {
		content: "";
		display: none; /* submenus are always expanded in the drawer */
	}
	.primary-menu .sub-menu {
		position: static;
		opacity: 1;
		visibility: visible;
		transform: none;
		border: 0;
		box-shadow: none;
		padding: 0 0 8px 18px;
		margin: 0;
		display: block;
	}
	.primary-menu .sub-menu a { padding: 10px 6px; }
	.primary-menu .sub-menu li:first-child { border-top: 1px dashed var(--agri-border); }

	/* Toggle becomes a close button floating over the drawer */
	.menu-toggle {
		position: relative;
		z-index: 1001;
		background: var(--agri-cream);
	}
	.main-navigation.toggled .menu-toggle { position: fixed; top: 18px; right: 18px; }

	.header-actions { margin-left: auto; }
	.menu-language-switcher ul { padding: 10px 6px; }
}

/* ==========================================================================
   2. Tablet landscape / small laptops (992px – 1080px)
   ========================================================================== */
@media (min-width: 993px) and (max-width: 1080px) {
	.primary-menu > li > a { padding: 10px 9px; font-size: 0.9rem; }
	.site-title { font-size: 1.3rem; }
	.container { padding-left: 28px; padding-right: 28px; }
}

/* ==========================================================================
   3. ≤992px — tablets: single-column layouts & 2-col grids
   (kept = main.css rules, refined here)
   ========================================================================== */
@media (max-width: 992px) {
	.section { padding: 60px 0 54px; }
	.section-header { margin-bottom: 36px; }

	.hero-section { padding: 96px 0; }
	.hero-title { font-size: clamp(2rem, 6vw, 3rem); }

	.stats-grid { gap: 30px 16px; }

	/* Commodity single page: card order → content first, price box second */
	.commodity-layout { display: flex; flex-direction: column; }
	.commodity-article { order: 1; }
	.commodity-aside { order: 2; }
	.commodity-aside .price-box { order: 2; }
	.commodity-aside .spec-box { order: 1; }

	/* Service list becomes full-width rows under the content */
	.service-aside { flex-direction: column; }

	.team-grid { grid-template-columns: repeat(2, 1fr); }

	.footer-widgets-inner { gap: 28px; }

	/* Trust bar: 3 per row */
	.trust-bar { gap: 18px; padding: 18px 20px; }
	.trust-items { gap: 18px 22px; }

	/* Lighter sticky handling on tablets (saves vertical space) */
	.main-header.is-sticky { box-shadow: var(--shadow-sm); }
}

/* ==========================================================================
   4. ≤768px — tablet portrait / large phones
   ========================================================================== */
@media (max-width: 768px) {
	body { font-size: 15.5px; }

	.top-bar .top-bar-right { display: none; } /* keep phones clean: contact info only */
	.top-bar-inner { justify-content: center; }

	.main-header-inner { gap: 14px; padding-top: 12px; padding-bottom: 12px; }
	.site-branding img { max-width: 170px; max-height: 56px; }
	.header-quote { display: none; }

	.hero-section { padding: 84px 0 76px; background-attachment: scroll; }
	.hero-text { font-size: 1rem; }
	.hero-buttons { gap: 10px; }

	.page-header { padding: 40px 0 36px; }
	.page-title { font-size: 1.7rem; }

	.cta-inner { gap: 22px; }
	.cta-phone { font-size: 1rem; }

	.commodity-body { padding: 18px; }
	.stat-number { font-size: 2rem; }
	.stat-plus { font-size: 1.3rem; }

	.testimonial-slide { padding: 20px 8px; }
	.testimonial-slide p, .testimonial-slide > * { font-size: 1.02rem; }

	/* Spec/price boxes full width & no sticky (already reset) */
	.price-box, .spec-box, .qc-box { padding: 20px; }

	/* Contact page */
	.rfq-panel { padding: 22px 18px; }
	.contact-map iframe { min-height: 300px; }

	/* Widgets spend less padding on small screens */
	.widget { padding: 20px; }

	/* Post navigation stacks neatly */
	.post-navigation { grid-template-columns: 1fr; gap: 14px; }
	.post-navigation .nav-next { grid-column: 1; text-align: left; }

	/* Comments comfortable on narrower screens */
	.comment-list .children { padding-left: 18px; }
	.comment-meta { flex-direction: column; gap: 4px; }

	/* Inputs ≥16px — prevents iOS auto-zoom on focus */
	.agri-field input,
	.agri-field textarea,
	.agri-field select,
	.search-field,
	.comment-form input:not([type="submit"]):not([type="checkbox"]),
	.comment-form textarea,
	.wpcf7-form-control:not(.wpcf7-submit),
	.wpforms-field input:not([type="submit"]):not([type="checkbox"]):not([type="radio"]),
	.wpforms-field textarea,
	.fluentform .ff-el-form-control,
	.gform_wrapper input:not([type="submit"]):not([type="checkbox"]):not([type="radio"]),
	.gform_wrapper textarea,
	.woocommerce form .form-row input.input-text,
	.woocommerce form .form-row textarea,
	.woocommerce form .form-row select,
	.woocommerce .quantity .qty {
		font-size: 16px;
	}

	/* Chips & dots = larger touch targets */
	.filter-chip { padding: 10px 20px; min-height: 44px; display: inline-flex; align-items: center; }
	.testimonial-dots .dot { width: 12px; height: 12px; margin: 4px; }
	.search-toggle, .header-cart { width: 44px; height: 44px; }

	.cta-section { padding: 48px 0; text-align: center; }
	.error-404 { padding: 64px 0; }

	.back-to-top { width: 44px; height: 44px; right: calc(18px + env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom)); }
}

/* ==========================================================================
   5. ≤640px — phones (grids go single column — see main.css — plus extras)
   ========================================================================== */
@media (max-width: 640px) {
	.team-grid .team-photo { border-radius: var(--radius); }

	/* Header search panel: full-bleed, tall field */
	.header-search-panel.open { max-height: none; }
	.header-search-panel .search-field { min-height: 50px; }

	/* Commodity cards: image trims down so content is visible sooner */
	.commodity-media, .post-card-media { aspect-ratio: 16 / 10; }

	/* Related section spacing */
	.section.related-commodities { padding: 48px 0; }

	/* Footer legal/copyright centered */
	.footer-menus { justify-content: center; }

	/* Careers: full-width tappable cards */
	.career-item { padding: 18px; }

	/* WooCommerce checkout fields full width */
	.woocommerce form .form-row-first,
	.woocommerce form .form-row-last,
	.woocommerce-page form .form-row-first,
	.woocommerce-page form .form-row-last { width: 100%; float: none; margin-right: 0; }
}

/* ==========================================================================
   6. ≤480px — small phones
   ========================================================================== */
@media (max-width: 480px) {
	.container { padding-left: 18px; padding-right: 18px; }

	.hero-section { padding: 72px 0 64px; }
	.hero-subtitle { font-size: 0.72rem; letter-spacing: 0.1em; padding: 6px 14px; }

	.section { padding: 48px 0; }
	.section-kicker { font-size: 0.72rem; }

	.trust-label { display: none; }
	.trust-item { font-size: 0.85rem; }

	.commodity-meta { flex-direction: column; align-items: flex-start; }
	.commodity-meta .commodity-link { margin-top: 2px; }

	.btn, button.btn, a.btn { width: 100%; justify-content: center; }
	.section-footer .btn, .cmt-actions .btn,
	.price-box .btn, .error-404-links .btn,
	.post-navigation .btn { width: 100%; }
	.error-404-links { flex-direction: column; }

	.spec-table th, .spec-table td { font-size: 0.85rem; padding: 9px 6px; }

	.price-table td { flex-wrap: wrap; }

	.stats-grid { grid-template-columns: repeat(2, 1fr); }

	.single-title { font-size: 1.55rem; }

	.footer-widgets { padding: 44px 0 26px; }
}

/* ==========================================================================
   7. ≤360px — very small phones
   ========================================================================== */
@media (max-width: 360px) {
	.site-title { font-size: 1.15rem; }
	.site-logo-icon { width: 38px; height: 38px; }
	.site-logo-icon svg { width: 22px; height: 22px; }
	.hero-title { font-size: 1.7rem; }
	.stat-number { font-size: 1.7rem; }
	.card, .commodity-body, .service-card, .post-card-body { padding: 16px; }
}

/* ==========================================================================
   8. Landscape phones & tablets (short height)
   ========================================================================== */
@media (max-height: 520px) and (orientation: landscape) {
	.hero-section { padding: 56px 0; }
	.main-header-inner { padding-top: 8px; padding-bottom: 8px; }
	.section { padding: 40px 0; }
	.stats-section { padding: 36px 0; }
	.cta-section { padding: 36px 0; }
	.comment-list .children { padding-left: 12px; }
}

/* ==========================================================================
   9. Touch devices — no hover-dependent interactions
   ========================================================================== */
@media (hover: none) {
	.commodity-card:hover,
	.service-card:hover,
	.post-card:hover,
	.market-item:hover,
	.value-card:hover,
	.career-item:hover { transform: none; box-shadow: var(--shadow-sm); }

	/* Sub-menus must open on tap: keep first tap as navigation when no children expanded is not needed (drawer handles it), on desktop-width touch (iPad landscape >1080px) show submenu on :focus-visible */
	.primary-menu li > a { -webkit-touch-callout: none; }
}

/* iPad landscape (1024–1080) with full desktop header occasionally shows the
   drawer toggle — the 1080px rule above already covers it. */

/* ==========================================================================
   9b. Menu fluidity — sizable on tablet & phone without distorting
   ========================================================================== */

/* Flex safety: logo, toggle, icons and actions never squish or stretch */
.main-header-inner { gap: clamp(12px, 2vw, 24px); }
.site-branding,
.menu-toggle,
.search-toggle,
.header-cart,
.header-actions { flex: none; }
.main-navigation { min-width: 0; }
.site-branding { min-width: 0; }
.site-branding img { max-width: min(220px, 44vw); }

/* Drawer width = fluid with viewport, never overflows, never too narrow */
@media (max-width: 1080px) {
	.primary-menu {
		width: clamp(280px, 78vw, 420px);
		max-width: 94vw;
	}
	.primary-menu li { min-width: 0; }
	.primary-menu > li > a {
		white-space: normal;
		overflow-wrap: break-word;
		font-size: clamp(0.96rem, 2.6vw, 1.05rem);
	}
	.site-branding img { max-width: min(170px, 42vw); }
}

/* Tablets: comfortably wider fluid drawer */
@media (min-width: 720px) and (max-width: 1080px) {
	.primary-menu {
		width: clamp(400px, 52vw, 500px);
		max-width: 94vw;
	}
	.primary-menu > li > a { font-size: 1.02rem; }
}

/* Tiny phones: icons stay reachable, logo scales down gracefully */
@media (max-width: 400px) {
	.menu-toggle, .search-toggle, .header-cart { width: 42px; height: 42px; }
	.site-branding img { max-width: 54vw; }
	.site-logo-icon { width: 40px; height: 40px; }
}

/* Header buttons: hidden below 1100px unless the builder opt-in is on */
@media (max-width: 1100px) {
	.header-actions .header-btn { display: none; }
	.agri-show-btns-mobile .header-actions .header-btn {
		display: inline-flex;
		padding: 9px 14px;
		font-size: 0.8rem;
	}
}
@media (max-width: 480px) {
	.agri-show-btns-mobile .header-actions .header-btn { padding: 8px 12px; font-size: 0.75rem; }
}

/* Centered header collapses neatly back into a single row */
@media (max-width: 1080px) {
	.header-layout-centered .main-header-inner {
		flex-direction: row;
		flex-wrap: nowrap;
		justify-content: space-between;
		gap: 14px;
	}
	.header-layout-centered .header-actions { position: static; }
}

/* ==========================================================================
   9c. Compact header layout — full drawer at EVERY width
   ========================================================================== */
.header-layout-compact .menu-toggle { display: inline-flex; }
.header-layout-compact .main-navigation { position: static; }
.header-layout-compact .main-navigation .primary-menu {
	position: fixed;
	top: 0;
	right: 0;
	left: auto;
	width: clamp(280px, 60vw, 440px);
	max-width: 94vw;
	height: 100%;
	height: 100dvh;
	background: var(--agri-white);
	flex-direction: column;
	align-items: stretch;
	gap: 0;
	padding: 76px 22px 32px;
	box-shadow: -12px 0 40px rgba(23, 41, 28, 0.18);
	display: flex;
	overflow-y: auto;
	-webkit-overflow-scrolling: touch;
	overscroll-behavior: contain;
	transform: translateX(105%);
	transition: transform 0.32s ease;
	z-index: 999;
}
.header-layout-compact .main-navigation.toggled .primary-menu { transform: translateX(0); }
.header-layout-compact .main-navigation.toggled::before {
	content: "";
	position: fixed;
	inset: 0;
	background: rgba(22, 48, 31, 0.55);
	backdrop-filter: blur(2px);
	z-index: 998;
}
.header-layout-compact .main-navigation.toggled .menu-toggle {
	position: fixed;
	top: 18px;
	right: 18px;
}
.header-layout-compact .primary-menu > li { position: relative; border-bottom: 1px solid var(--agri-border); }
.header-layout-compact .primary-menu > li > a {
	padding: 15px 58px 15px 6px;
	font-size: 1.02rem;
	border-radius: 0;
	white-space: normal;
	overflow-wrap: break-word;
}
.header-layout-compact .primary-menu > li > a:hover { background: transparent; color: var(--agri-primary); }
.header-layout-compact .primary-menu .sub-menu {
	position: static;
	opacity: 1;
	visibility: visible;
	transform: none;
	border: 0;
	box-shadow: none;
	padding: 0 0 0 16px;
	margin: 0;
	display: none;
	background: transparent;
	list-style: none;
}
.header-layout-compact .primary-menu li.open > .sub-menu { display: block; }
.header-layout-compact .primary-menu .sub-menu a {
	display: block;
	padding: 10px 6px;
	font-size: 0.94rem;
	color: var(--agri-text);
}
.header-layout-compact .submenu-toggle {
	display: inline-flex;
	position: absolute;
	right: 2px;
	top: 7px;
	width: 44px;
	height: 44px;
	border-radius: 10px;
	background: var(--agri-primary-light);
	color: var(--agri-primary);
	transition: var(--transition);
}
.header-layout-compact .submenu-toggle svg { pointer-events: none; width: 18px; height: 18px; transition: transform 0.25s ease; }
.header-layout-compact .primary-menu li.open > .submenu-toggle { background: var(--agri-primary); color: #fff; }
.header-layout-compact .primary-menu li.open > .submenu-toggle svg { transform: rotate(180deg); }

/* Compact mega panels behave like the drawer accordion everywhere */
.header-layout-compact .primary-menu .mega-menu-panel {
	background: var(--agri-cream);
	border-radius: 14px;
	margin: 4px 0 14px;
	padding: 14px 18px;
}
.header-layout-compact .primary-menu .mega-menu-panel .mega-menu-col > a {
	font-family: var(--font-heading);
	font-weight: 800;
	color: var(--agri-primary-dark);
	font-size: 0.95rem;
}
.header-layout-compact .primary-menu .mega-menu-panel .sub-menu {
	display: block;
	border-left: 2px solid var(--agri-border);
	margin: 4px 0 8px 2px;
}

/* ==========================================================================
   10. WooCommerce device tweaks (augments woocommerce.css)
   ========================================================================== */
@media (max-width: 1080px) {
	.woocommerce ul.products.columns-4,
	.woocommerce ul.products.columns-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
	.woocommerce ul.products,
	.woocommerce .related ul.products,
	.woocommerce .upsells ul.products { grid-template-columns: 1fr 1fr; gap: 14px; }
	.woocommerce ul.products li.product .woocommerce-loop-product__title { font-size: 0.88rem; padding: 0 10px; }
	.woocommerce ul.products li.product .price { font-size: 0.9rem; }
	.woocommerce ul.products li.product .button { font-size: 0.75rem !important; padding: 9px 12px !important; }
	.woocommerce table.shop_table { font-size: 0.85rem; }
	.woocommerce table.shop_table td, .woocommerce table.shop_table th { padding: 8px; }
}
@media (max-width: 380px) {
	.woocommerce ul.products, .woocommerce .related ul.products, .woocommerce .upsells ul.products { grid-template-columns: 1fr; }
}
