/**
 * Text4Stuff theme customizations
 * - Category/location archives: theme container width, hide empty sidebar
 * - Search/sub-category pages: top filters, theme container width
 * - Single ad pages: hide left jump nav, widen image gallery
 */

/* Use theme .adt-container width (1420px max) — same as homepage. */

/* -------------------------------------------------------------------------
 * Category + location archives
 * ------------------------------------------------------------------------- */

body.tax-ad_cats .adt-ads-filter-content-wrapper .adt-ads-filter-sidebar:not(:has(.accordion-item)),
body.tax-ad_country .adt-ads-filter-content-wrapper .adt-ads-filter-sidebar:not(:has(.accordion-item)) {
	display: none !important;
	width: 0 !important;
	min-width: 0 !important;
	margin: 0 !important;
	padding: 0 !important;
}

body.tax-ad_cats .adt-ads-filter-content-wrapper:not(:has(.adt-ads-filter-sidebar .accordion-item)),
body.tax-ad_country .adt-ads-filter-content-wrapper:not(:has(.adt-ads-filter-sidebar .accordion-item)) {
	gap: 0;
}

body.tax-ad_cats .adt-ads-filter-content-wrapper:not(:has(.adt-ads-filter-sidebar .accordion-item)) .adt-ads-filter-content,
body.tax-ad_country .adt-ads-filter-content-wrapper:not(:has(.adt-ads-filter-sidebar .accordion-item)) .adt-ads-filter-content {
	width: 100% !important;
	max-width: 100% !important;
	flex: 1 1 100%;
}

/* -------------------------------------------------------------------------
 * Search / sub-category pages
 * ------------------------------------------------------------------------- */

body.t4s-search-redesign .adt-ads-filter-content-wrapper {
	flex-direction: column;
	gap: 20px;
}

body.t4s-search-redesign .adt-ads-filter-sidebar {
	width: 100% !important;
	max-width: 100% !important;
	min-width: 0 !important;
	order: 1;
	position: relative;
}

body.t4s-search-redesign .adt-ads-filter-content {
	width: 100% !important;
	max-width: 100% !important;
	order: 2;
}

body.t4s-search-redesign .adt-ads-filter-sidebar #adforest-ajax-sidebar,
body.t4s-search-redesign .adt-ads-filter-sidebar .adforest-ajax-sidebar {
	width: 100%;
}

body.t4s-search-redesign .adt-ads-filter-sidebar .mobile-filter-heading h1 {
	margin-bottom: 0;
}

body.t4s-subcategory-view .adt-ads-filter-sidebar .mobile-filter-heading {
	display: none !important;
}

body.t4s-parent-category-view .adt-ads-filter-sidebar .mobile-filter-heading {
	display: none !important;
}

body.t4s-search-redesign .adt-ads-filter-content .expand-collapse.adforest-new-filter {
	display: none !important;
}

/* Keep server-rendered filter panels closed until search-layout.js finishes. */
body.t4s-search-redesign:not(.t4s-layout-ready) .adt-ads-filter-sidebar .accordion-collapse {
	display: none !important;
	visibility: hidden !important;
	height: 0 !important;
	max-height: 0 !important;
	overflow: hidden !important;
	opacity: 0 !important;
	pointer-events: none !important;
}

body.t4s-search-redesign:not(.t4s-layout-ready) .adt-ads-filter-sidebar .accordion-item:has(.accordion-collapse.show) {
	z-index: auto !important;
}

body.t4s-search-redesign .adt-breadcrumb .breadcrumb:not(.t4s-search-breadcrumb-ready) {
	visibility: hidden;
}

body.t4s-search-redesign .adt-breadcrumb .breadcrumb.t4s-search-breadcrumb-ready {
	visibility: visible;
}

body.t4s-search-redesign .t4s-subcategory-header {
	margin: 0 0 20px;
	padding: 0 0 16px;
	border-bottom: 1px solid #ececec;
}

body.t4s-search-redesign .t4s-subcategory-header__title {
	margin: 0 0 8px;
	font-size: clamp(1.5rem, 2vw, 2rem);
	font-weight: 600;
	line-height: 1.2;
	color: #242424;
}

body.t4s-search-redesign .t4s-subcategory-header__meta {
	margin: 0;
	font-size: 0.95rem;
	color: #666;
}

body.t4s-subcategory-view .adt-category-list-sidebar .btn-outline-secondary,
body.t4s-subcategory-view .adt-category-list-sidebar a.btn.btn-sm,
body.t4s-parent-category-view .adt-category-list-sidebar .btn-outline-secondary,
body.t4s-parent-category-view .adt-category-list-sidebar a.btn.btn-sm {
	display: none !important;
}

body.t4s-subcategory-view .adt-category-list-sidebar li.t4s-subcategory-active .adt-category-box {
	background: #f5f8ff;
	border-radius: 6px;
}

body.t4s-subcategory-view .adt-category-list-sidebar li.t4s-subcategory-active .category-meta a:last-child {
	font-weight: 600;
}

body.t4s-search-redesign .t4s-filter-actions-bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	flex-wrap: wrap;
	margin-bottom: 12px;
}

body.t4s-search-redesign .t4s-filter-actions-bar .adforest-ajax-toolbar {
	margin-bottom: 0;
	flex: 1 1 auto;
}

body.t4s-search-redesign .t4s-category-back-btn {
	white-space: nowrap;
	margin-left: auto;
}

body.t4s-search-redesign .adt-category-list-sidebar .adt-category-box {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
}

body.t4s-search-redesign .adt-category-list-sidebar .category-meta {
	display: flex;
	align-items: center;
	gap: 10px;
	min-width: 0;
	flex: 1 1 auto;
}

body.t4s-search-redesign .adt-category-list-sidebar .category-meta a:last-child {
	white-space: normal;
	line-height: 1.3;
}

body.t4s-search-redesign .adt-category-list-sidebar .listing-count {
	white-space: nowrap;
	flex-shrink: 0;
	font-size: 0.75rem;
}

body.t4s-search-redesign .adt-category-list-sidebar li.t4s-category-group-header .adt-category-box {
	background: #f7f7f7;
	border-radius: 6px;
}

body.t4s-search-redesign .adt-category-list-sidebar li.t4s-category-group-header .category-meta a:last-child {
	font-weight: 600;
}

body.t4s-search-redesign .adt-category-list-sidebar li.t4s-subcategory-nested {
	padding-left: 16px;
}

body.t4s-search-redesign .adt-category-list-sidebar li.t4s-subcategory-nested .img-box img,
body.t4s-search-redesign .adt-category-list-sidebar li.t4s-subcategory-nested .img-box {
	width: 34px;
	height: 34px;
}

body.t4s-search-redesign .adt-ads-sort-box {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: space-between;
	gap: 12px 20px;
	margin-bottom: 16px;
	padding-bottom: 16px;
	border-bottom: 1px solid #ececec;
}

body.t4s-search-redesign .adt-ads-sort-box h3 {
	margin: 0;
	font-size: 1.05rem;
}

body.t4s-search-redesign .adt-sort-filters {
	display: flex;
	align-items: center;
	gap: 12px;
}

body.t4s-search-redesign .tag-search {
	width: 100%;
	margin: 0 0 16px;
}

body.t4s-search-redesign .alert-for-topbar {
	margin-bottom: 20px;
}

body.t4s-search-redesign .alert-for-topbar + #adf-active-filters.is-visible {
	margin-top: 4px;
	margin-bottom: 20px;
}

/* Category pill is redundant when header/breadcrumb already show the category. */
body.t4s-subcategory-view .tag-search,
body.t4s-parent-category-view .tag-search {
	display: none !important;
}

@media (min-width: 992px) {
	body.t4s-search-redesign .adt-ads-filter-sidebar .accordion {
		display: grid;
		grid-template-columns: repeat(3, minmax(0, 1fr));
		gap: 12px;
		align-items: start;
	}

	body.t4s-search-redesign .adt-ads-filter-sidebar .accordion-item {
		position: relative;
		margin-bottom: 0;
	}

	body.t4s-search-redesign .adt-ads-filter-sidebar .accordion-item:has(.accordion-collapse.show) {
		z-index: 40;
	}

	body.t4s-search-redesign .adt-ads-filter-sidebar .accordion-item .accordion-collapse {
		position: absolute;
		top: calc(100% - 1px);
		left: 0;
		right: auto;
		z-index: 41;
		width: min(360px, 92vw);
		min-width: 320px;
		max-height: min(460px, 65vh);
		overflow-x: hidden;
		overflow-y: auto;
		background: #fff;
		border: 1px solid #e5e5e5;
		border-top: 0;
		border-radius: 0 0 8px 8px;
		box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
	}

	body.t4s-search-redesign .adt-ads-filter-sidebar .accordion-item.t4s-category-filter-item .accordion-collapse {
		width: min(380px, 92vw);
		min-width: 340px;
	}

	body.t4s-search-redesign .adt-ads-filter-sidebar .accordion-item .accordion-collapse.show {
		max-height: min(460px, 65vh);
	}

	body.t4s-search-redesign .adt-ads-filter-sidebar .accordion-item .accordion-body {
		padding: 12px;
	}

	body.t4s-parent-category-view .adt-ads-filter-sidebar .accordion-item:has(.accordion-button),
	body.t4s-subcategory-view .adt-ads-filter-sidebar .accordion-item:has(.accordion-button) {
		min-width: 0;
	}

	body.t4s-search-redesign .adt-ads-filter-sidebar .mobile-filters-btn {
		display: none !important;
	}

	body.t4s-search-redesign .adt-ads-filter-sidebar .mobile-filters,
	body.t4s-search-redesign .adt-ads-filter-sidebar #adforest-ajax-sidebar.mobile-filters {
		display: block !important;
		position: static !important;
		height: auto !important;
		overflow: visible !important;
		padding: 0 !important;
		background: transparent !important;
	}
}

@media (min-width: 1200px) {
	body.t4s-search-redesign .adt-ads-filter-sidebar .accordion {
		grid-template-columns: repeat(6, minmax(0, 1fr));
	}
}

@media (max-width: 991.98px) {
	body.t4s-search-redesign .adt-ads-filter-sidebar .accordion {
		display: block;
	}

	/* Theme search-ux.js adds a duplicate blue Filters button; keep the red fixed one. */
	body.t4s-search-redesign #adf-open-filters,
	body.t4s-search-redesign .adf-mobile-filters-btn,
	body.t4s-search-redesign .adf-filters-backdrop {
		display: none !important;
	}

	/* Category is already set on category/search pages — hide header search bar picker. */
	body.t4s-search-redesign .adt-top-search-bar div:has(> select[name="cat_id"]),
	body.t4s-search-redesign .adt-top-search-bar .adt-search-area form > select[name="cat_id"],
	body.tax-ad_cats .adt-top-search-bar div:has(> select[name="cat_id"]),
	body.tax-ad_cats .adt-top-search-bar .adt-search-area form > select[name="cat_id"] {
		display: none !important;
	}
}

/* -------------------------------------------------------------------------
 * Single ad detail (Style 1) — hide left jump nav, widen gallery
 * ------------------------------------------------------------------------- */

@media (min-width: 992px) {
	body.t4s-ad-detail-redesign .adt-ad-detail-content-wrapper .left-side-bar {
		display: none !important;
		width: 0 !important;
		min-width: 0 !important;
		margin: 0 !important;
		padding: 0 !important;
		overflow: hidden;
	}

	body.t4s-ad-detail-redesign .adt-ad-detail-content-wrapper .ad-detail-middle-content {
		width: calc(100% - 339px) !important;
		flex: 1 1 auto;
		min-width: 0;
		max-width: none;
	}
}
