/**
 * CPF Criteria Chips — CellphoneS-inspired
 * All selectors scoped under .lmkt-cpf--chips
 * @since 5.5.0
 */

/* ===================== LAYOUT ===================== */
.lmkt-cpf--chips {
	position: relative;
	margin-bottom: 16px;
}

/* ---- Theme hardening (Flatsome uppercases + underlines buttons/links) ---- */
body .lmkt-cpf--chips a,
body .lmkt-cpf--chips button,
body .lmkt-cpf-chips__modal a,
body .lmkt-cpf-chips__modal button {
	text-transform: none !important;
	letter-spacing: normal !important;
	text-decoration: none !important;
	box-shadow: none !important;
}
body .lmkt-cpf--chips button,
body .lmkt-cpf-chips__modal button {
	line-height: normal !important;
	min-height: 0 !important;
	margin: 0;
}

/* ===================== SUBCATEGORY ROW ===================== */
.lmkt-cpf-chips__subcats {
	display: flex;
	align-items: flex-start;
	gap: 10px;
	margin-bottom: 12px;
	padding-bottom: 10px;
	border-bottom: 1px solid #f1f5f9;
}
.lmkt-cpf-chips__subcats-label {
	flex: 0 0 auto;
	padding-top: 7px;
	font-size: 13px;
	font-weight: 600;
	color: #64748b;
	white-space: nowrap;
}
.lmkt-cpf-chips__subcats-track {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	min-width: 0;
}

/* No label: the chips get the full width of the container. */
.lmkt-cpf-chips__subcats--nolabel {
	display: block;
}
.lmkt-cpf-chips__subcats--nolabel .lmkt-cpf-chips__subcats-track {
	width: 100%;
}

/* --- "Hàng ngang": one single line that scrolls horizontally --------------- */
.lmkt-cpf-chips__subcats--scroll {
	align-items: center;
}
.lmkt-cpf-chips__subcats--scroll .lmkt-cpf-chips__subcats-track {
	flex-wrap: nowrap;
	overflow-x: auto;
	overflow-y: hidden;
	scroll-behavior: smooth;
	-webkit-overflow-scrolling: touch;
	padding-bottom: 2px;
	/* Fade the right edge so it reads as "there is more to the right". */
	-webkit-mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 28px), transparent 100%);
	mask-image: linear-gradient(to right, #000 0, #000 calc(100% - 28px), transparent 100%);
	/* Hide the scrollbar: a native bar with arrow buttons is visually heavier
	   than the chips themselves. The fade + touch/wheel scrolling carry it. */
	scrollbar-width: none;
	-ms-overflow-style: none;
}
.lmkt-cpf-chips__subcats--scroll .lmkt-cpf-chips__subcats-track::-webkit-scrollbar {
	width: 0;
	height: 0;
	display: none;
}
.lmkt-cpf-chips__subcats--scroll .lmkt-cpf-chips__subcat,
.lmkt-cpf-chips__subcats--scroll .lmkt-cpf-chips__subcat-more {
	flex: 0 0 auto;
}
.lmkt-cpf-chips__subcat {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 6px 12px;
	background: #f8fafc;
	color: #334155;
	border: 1px solid #e2e8f0;
	border-radius: 20px;
	font-size: 13px;
	line-height: 1.3;
	text-decoration: none;
	white-space: nowrap;
	transition: all .15s;
}
.lmkt-cpf-chips__subcat:hover {
	background: #eef2f7;
	border-color: #cbd5e1;
	color: #0f172a;
}
.lmkt-cpf-chips__subcat--active {
	background: #fff;
	color: #e53e3e;
	border-color: #e53e3e;
	font-weight: 600;
}
.lmkt-cpf-chips__subcat--all {
	border-style: dashed;
}
/* --- Category thumbnail ---------------------------------------------------- */
.lmkt-cpf-chips__subcat-icon {
	width: var(--cpf-chips-subcat-icon, 26px);
	height: var(--cpf-chips-subcat-icon, 26px);
	/* border-box so the configured size IS the outer size and matches the
	   width/height attributes — otherwise the border adds 2px and the row
	   shifts once the image loads. */
	box-sizing: border-box;
	object-fit: cover;
	border-radius: 50%;
	flex-shrink: 0;
	display: block;
	background: #fff;
	border: 1px solid #e2e8f0;
	/* Never inherit a theme's img sizing (Flatsome sets width:100% on images). */
	max-width: none !important;
	min-width: 0;
	margin: 0 !important;
	padding: 0 !important;
	box-shadow: none !important;
}
.lmkt-cpf-chips__subcats--icons .lmkt-cpf-chips__subcat {
	padding: 4px 12px 4px 4px;
	/* Every chip in the row is the same height whether or not the category has a
	   thumbnail, otherwise the row looks ragged and offsetTop varies per chip. */
	min-height: calc(var(--cpf-chips-subcat-icon, 26px) + 10px);
}
.lmkt-cpf-chips__subcats--icons .lmkt-cpf-chips__subcat--all,
.lmkt-cpf-chips__subcats--icons .lmkt-cpf-chips__subcat--no-icon {
	/* Chips without a thumbnail keep the normal padding so the row stays even. */
	padding: 4px 12px;
}
.lmkt-cpf-chips__subcats--icons .lmkt-cpf-chips__subcats-track {
	align-items: stretch;
}
.lmkt-cpf-chips__subcat--active .lmkt-cpf-chips__subcat-icon {
	border-color: #e53e3e;
}
.lmkt-cpf-chips__subcat-count {
	font-size: 11px;
	color: #94a3b8;
	font-weight: 500;
}
.lmkt-cpf-chips__subcat--active .lmkt-cpf-chips__subcat-count { color: #f0a0a0; }
.lmkt-cpf-chips__subcat-hidden[hidden] { display: none !important; }
.lmkt-cpf-chips__subcat-more {
	padding: 6px 12px;
	background: transparent;
	color: #6b7280;
	border: 1px dashed #cbd5e1;
	border-radius: 20px;
	font-size: 13px;
	line-height: 1.3;
	cursor: pointer;
	white-space: nowrap;
	transition: all .15s;
}
.lmkt-cpf-chips__subcat-more:hover {
	background: #f8fafc;
	color: #334155;
	border-color: #94a3b8;
}

/* Subcategories inside a popover / the modal use a grid, not a row. */
.lmkt-cpf-chips__popover-body--subcats,
.lmkt-cpf-chips__modal-options--subcats {
	display: grid;
	grid-template-columns: repeat(var(--cpf-chips-cols, 3), 1fr);
	gap: 6px;
}
.lmkt-cpf-chips__popover-body--subcats .lmkt-cpf-chips__subcat,
.lmkt-cpf-chips__modal-options--subcats .lmkt-cpf-chips__subcat {
	border-radius: 6px;
	justify-content: flex-start;
	white-space: normal;
}
.lmkt-cpf-chips__popover-body--subcats .lmkt-cpf-chips__subcat-name,
.lmkt-cpf-chips__modal-options--subcats .lmkt-cpf-chips__subcat-name {
	overflow: hidden;
	text-overflow: ellipsis;
}

/* ===================== HEADING ===================== */
.lmkt-cpf-chips__heading {
	font-size: 15px;
	font-weight: 700;
	color: #1e293b;
	margin-bottom: 10px;
}

/* ===================== CHIP BAR ===================== */
.lmkt-cpf-chips__bar {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	align-items: center;
	margin-bottom: 10px;
}

/* Master filter button */
.lmkt-cpf-chips__master-btn {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 8px 16px;
	background: #fff;
	border: 2px solid #e53e3e;
	border-radius: 8px;
	color: #e53e3e;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	transition: all .15s;
	text-transform: none;
}
.lmkt-cpf-chips__master-btn:hover {
	background: #fef2f2;
}
.lmkt-cpf-chips__badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 20px;
	height: 20px;
	padding: 0 6px;
	background: #e53e3e;
	color: #fff;
	border-radius: 10px;
	font-size: 11px;
	font-weight: 700;
}

/* ===================== GROUP DROPDOWN CHIP ===================== */
.lmkt-cpf-chips__group {
	position: relative;
}
.lmkt-cpf-chips__trigger {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 8px 14px;
	background: #f8fafc;
	border: 1.5px solid #d1d5db;
	border-radius: 8px;
	color: #475569;
	font-size: 13px;
	font-weight: 500;
	cursor: pointer;
	transition: all .15s;
	white-space: nowrap;
	text-transform: none;
}
.lmkt-cpf-chips__trigger:hover {
	background: #e2e8f0;
	border-color: #94a3b8;
}
.lmkt-cpf-chips__group--active .lmkt-cpf-chips__trigger {
	border-color: #e53e3e;
	color: #e53e3e;
	background: #fff;
	font-weight: 600;
}
.lmkt-cpf-chips__arrow {
	font-size: 10px;
	transition: transform .2s;
}
.lmkt-cpf-chips__group.is-open .lmkt-cpf-chips__arrow {
	transform: rotate(180deg);
}
.lmkt-cpf-chips__trigger-count {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 18px;
	height: 18px;
	padding: 0 5px;
	background: #e53e3e;
	color: #fff;
	border-radius: 9px;
	font-size: 11px;
	font-weight: 700;
}

/* Subcategory dropdown chip: navigation, so it reads slightly differently from
   the criteria chips next to it. */
.lmkt-cpf-chips__group--subcats .lmkt-cpf-chips__trigger {
	background: #fff;
	border-style: solid;
	border-color: #cbd5e1;
	color: #334155;
	font-weight: 600;
}
.lmkt-cpf-chips__group--subcats .lmkt-cpf-chips__trigger:hover {
	border-color: #94a3b8;
	background: #f8fafc;
}
.lmkt-cpf-chips__group--subcats .lmkt-cpf-chips__popover {
	min-width: 320px;
}

/* "+N tiêu chí" overflow button — opens the master modal */
.lmkt-cpf-chips__more-groups {
	display: inline-flex;
	align-items: center;
	padding: 8px 14px;
	background: transparent;
	border: 1.5px dashed #cbd5e1;
	border-radius: 8px;
	color: #64748b;
	font-size: 13px;
	font-weight: 500;
	cursor: pointer;
	white-space: nowrap;
	transition: all .15s;
}
.lmkt-cpf-chips__more-groups:hover {
	background: #f8fafc;
	border-color: #94a3b8;
	color: #334155;
}

/* ===================== POPOVER ===================== */
.lmkt-cpf-chips__popover {
	display: none;
	position: absolute;
	top: calc(100% + 6px);
	left: 0;
	z-index: 100002;
	background: #fff;
	border: 1px solid #e5e7eb;
	border-radius: 12px;
	box-shadow: 0 4px 24px rgba(0,0,0,0.12);
	min-width: 280px;
	max-width: 480px;
	overflow: hidden;
}
.lmkt-cpf-chips__group.is-open .lmkt-cpf-chips__popover {
	display: block;
}
.lmkt-cpf-chips__popover-body {
	display: grid;
	grid-template-columns: repeat(var(--cpf-chips-cols, 3), 1fr);
	gap: 6px;
	padding: 14px 16px;
	max-height: 300px;
	overflow-y: auto;
}

/* ===================== OPTIONS (shared popover + modal) ===================== */
.lmkt-cpf-chips__option {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 7px 12px;
	background: #f1f5f9;
	color: #475569;
	border: 1px solid #e2e8f0;
	border-radius: 6px;
	font-size: 13px;
	text-decoration: none;
	cursor: pointer;
	transition: all .15s;
	white-space: nowrap;
	text-align: center;
	justify-content: center;
}
.lmkt-cpf-chips__option:hover {
	background: #e2e8f0;
	color: #1e293b;
}
.lmkt-cpf-chips__option--active {
	background: #e53e3e;
	color: #fff;
	border-color: #e53e3e;
	font-weight: 600;
}
.lmkt-cpf-chips__option--active:hover {
	background: #dc2626;
}
.lmkt-cpf-chips__check {
	font-size: 11px;
}
.lmkt-cpf-chips__option-count {
	font-size: 11px;
	opacity: .65;
}

/* ===================== MODAL SEARCH ===================== */
.lmkt-cpf-chips__search-input {
	width: 100%;
	padding: 10px 14px;
	border: 1px solid #d1d5db;
	border-radius: 8px;
	font-size: 14px;
	background: #fff;
	color: #1e293b;
	box-shadow: none;
	margin: 0;
}
.lmkt-cpf-chips__search-input:focus {
	border-color: #e53e3e;
	outline: none;
}
.lmkt-cpf-chips__search-results {
	display: none;
	margin-top: 6px;
	max-height: 260px;
	overflow-y: auto;
	border: 1px solid #e5e7eb;
	border-radius: 8px;
	background: #fff;
}
.lmkt-cpf-chips__search-results a {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 10px;
	border-bottom: 1px solid #f1f5f9;
	color: #1e293b;
	font-size: 13px;
	text-decoration: none;
}
.lmkt-cpf-chips__search-results a:last-child { border-bottom: none; }
.lmkt-cpf-chips__search-results a:hover { background: #f8fafc; }
.lmkt-cpf-chips__search-results img {
	width: 36px;
	height: 36px;
	object-fit: cover;
	border-radius: 4px;
	flex-shrink: 0;
}

/* ===================== POPOVER FOOTER ===================== */
.lmkt-cpf-chips__popover-footer {
	display: flex;
	justify-content: flex-end;
	gap: 8px;
	padding: 10px 16px;
	border-top: 1px solid #f1f5f9;
	background: #fafafa;
}
.lmkt-cpf-chips__popover-close {
	padding: 6px 16px;
	background: #f1f5f9;
	color: #64748b;
	border: 1px solid #d1d5db;
	border-radius: 6px;
	font-size: 13px;
	cursor: pointer;
	transition: background .15s;
}
.lmkt-cpf-chips__popover-close:hover {
	background: #e2e8f0;
}
.lmkt-cpf-chips__popover-apply {
	padding: 6px 16px;
	background: #e53e3e;
	color: #fff;
	border-radius: 6px;
	font-size: 13px;
	font-weight: 600;
	text-decoration: none;
	transition: background .15s;
}
.lmkt-cpf-chips__popover-apply:hover {
	background: #dc2626;
	color: #fff;
}

/* ===================== ACTIVE FILTERS ("Đang lọc theo") ===================== */
.lmkt-cpf-chips__active-filters {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px;
	padding: 10px 0;
	border-top: 1px solid #f1f5f9;
}
.lmkt-cpf-chips__active-label {
	font-size: 13px;
	color: #64748b;
	font-weight: 500;
	margin-right: 4px;
}
.lmkt-cpf-chips__active-chip {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 5px 10px;
	background: #fff;
	color: #2563eb;
	border: 1.5px solid #2563eb;
	border-radius: 20px;
	font-size: 12px;
	font-weight: 600;
	text-decoration: none;
	white-space: nowrap;
	transition: all .15s;
}
.lmkt-cpf-chips__active-chip:hover {
	background: #eff6ff;
}
.lmkt-cpf-chips__active-group { opacity: .7; }
.lmkt-cpf-chips__active-remove { font-size: 10px; opacity: .6; }
.lmkt-cpf-chips__clear-all {
	padding: 5px 10px;
	background: #ef4444;
	color: #fff;
	border-radius: 20px;
	font-size: 12px;
	font-weight: 500;
	text-decoration: none;
	transition: background .15s;
}
.lmkt-cpf-chips__clear-all:hover {
	background: #dc2626;
}

/* ===================== MASTER MODAL ===================== */
.lmkt-cpf-chips__modal {
	display: none;
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	z-index: 100001;
	background: #fff;
	border-radius: 16px;
	box-shadow: 0 20px 60px rgba(0,0,0,0.2);
	width: 90vw;
	max-width: 720px;
	max-height: 85vh;
	overflow: hidden;
	flex-direction: column;
}
.lmkt-cpf-chips__modal.is-open {
	display: flex;
}
.lmkt-cpf-chips__modal-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 16px 20px;
	border-bottom: 1px solid #e5e7eb;
}
.lmkt-cpf-chips__modal-title {
	font-size: 16px;
	font-weight: 700;
	color: #1e293b;
}
.lmkt-cpf-chips__modal-close {
	background: none;
	border: none;
	font-size: 20px;
	cursor: pointer;
	color: #64748b;
	padding: 4px;
}
.lmkt-cpf-chips__modal-body {
	flex: 1;
	overflow-y: auto;
	padding: 16px 20px;
}
.lmkt-cpf-chips__modal-section {
	margin-bottom: 16px;
}
.lmkt-cpf-chips__modal-section-title {
	font-size: 14px;
	font-weight: 600;
	color: #334155;
	margin-bottom: 8px;
}
.lmkt-cpf-chips__modal-options {
	display: grid;
	grid-template-columns: repeat(var(--cpf-chips-cols, 3), 1fr);
	gap: 6px;
}
.lmkt-cpf-chips__modal-footer {
	display: flex;
	justify-content: center;
	gap: 12px;
	padding: 14px 20px;
	border-top: 1px solid #e5e7eb;
	background: #fafafa;
}
.lmkt-cpf-chips__modal-apply {
	flex: 1;
	text-align: center;
	padding: 10px 20px;
	background: #e53e3e;
	color: #fff;
	border-radius: 8px;
	font-weight: 600;
	font-size: 14px;
	text-decoration: none;
	transition: background .15s;
}
.lmkt-cpf-chips__modal-apply:hover { background: #dc2626; color: #fff; }
.lmkt-cpf-chips__modal-reset[hidden] { display: none !important; }
.lmkt-cpf-chips__modal-reset {
	text-align: center;
	padding: 10px 20px;
	background: #f1f5f9;
	color: #ef4444;
	border-radius: 8px;
	font-weight: 500;
	font-size: 14px;
	text-decoration: none;
}
.lmkt-cpf-chips__modal-reset:hover { background: #fef2f2; }

/* ===================== OVERLAY ===================== */
.lmkt-cpf-chips__overlay {
	display: none;
	position: fixed;
	top: 0; left: 0; right: 0; bottom: 0;
	background: rgba(0,0,0,0.4);
	z-index: 100000;
}
.lmkt-cpf-chips__overlay.is-open {
	display: block;
}

/* ===================== SORTING ===================== */
.lmkt-cpf-chips__sorting {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
	gap: 8px;
	margin-bottom: 12px;
	padding-top: 8px;
	border-top: 1px solid #f1f5f9;
}
.lmkt-cpf-chips__sorting-label {
	font-size: 14px;
	color: #64748b;
	font-weight: 500;
}
.lmkt-cpf-chips__sort {
	display: inline-flex;
	align-items: center;
	padding: 6px 14px;
	background: #f8fafc;
	color: #475569;
	border: 1px solid #e2e8f0;
	border-radius: 20px;
	font-size: 13px;
	text-decoration: none;
	cursor: pointer;
	transition: all .15s;
	white-space: nowrap;
}
.lmkt-cpf-chips__sort:hover {
	background: #e2e8f0;
}
.lmkt-cpf-chips__sort--active {
	background: #e53e3e;
	color: #fff;
	border-color: #e53e3e;
	font-weight: 600;
}

/* ===================== MOBILE ===================== */
@media (max-width: 768px) {
	.lmkt-cpf-chips__bar {
		overflow-x: auto;
		flex-wrap: nowrap;
		-webkit-overflow-scrolling: touch;
		padding-bottom: 4px;
	}
	.lmkt-cpf-chips__trigger,
	.lmkt-cpf-chips__master-btn {
		flex-shrink: 0;
	}

	/* Popover → bottom sheet on mobile */
	.lmkt-cpf-chips__popover {
		position: fixed;
		top: auto;
		bottom: 0;
		left: 0;
		right: 0;
		z-index: 100003;
		border-radius: 16px 16px 0 0;
		max-width: 100%;
		min-width: 100%;
		max-height: 70vh;
	}
	.lmkt-cpf-chips__popover-body {
		grid-template-columns: repeat(2, 1fr);
		max-height: 50vh;
	}

	/* Modal — shape driven by the admin "Mobile mode" setting.
	   Default (bottom sheet): slides up from the bottom, leaves the page visible.
	   Fullscreen: covers the viewport. */
	.lmkt-cpf-chips__modal {
		top: auto;
		bottom: 0;
		left: 0;
		right: 0;
		transform: none;
		width: 100vw;
		max-width: 100vw;
		height: auto;
		max-height: 88vh;
		border-radius: 16px 16px 0 0;
	}
	.lmkt-cpf--chips-mobile-fullscreen ~ .lmkt-cpf-chips__modal,
	.lmkt-cpf--chips-mobile-fullscreen .lmkt-cpf-chips__modal {
		top: 0;
		bottom: 0;
		height: 100vh;
		max-height: 100vh;
		border-radius: 0;
	}
	.lmkt-cpf-chips__modal-footer {
		padding-bottom: max(14px, env(safe-area-inset-bottom, 14px));
	}
	.lmkt-cpf-chips__modal-options,
	.lmkt-cpf-chips__modal-options--subcats,
	.lmkt-cpf-chips__popover-body--subcats {
		grid-template-columns: repeat(2, 1fr);
	}

	/* Subcategory row scrolls horizontally instead of wrapping */
	.lmkt-cpf-chips__subcats {
		flex-direction: column;
		gap: 6px;
	}
	.lmkt-cpf-chips__subcats-label {
		padding-top: 0;
	}
	.lmkt-cpf-chips__subcats-track {
		flex-wrap: nowrap;
		overflow-x: auto;
		-webkit-overflow-scrolling: touch;
		padding-bottom: 4px;
		width: 100%;
	}
	.lmkt-cpf-chips__subcat,
	.lmkt-cpf-chips__subcat-more {
		flex-shrink: 0;
	}
	/* Expanded state must wrap, otherwise "+N" reveals off-screen chips only.
	   Scoped to --wrap: the "hàng ngang" mode must stay on one line at every
	   width, and it never renders a "+N" button anyway. */
	.lmkt-cpf-chips__subcats--wrap .lmkt-cpf-chips__subcats-track:has(.lmkt-cpf-chips__subcat-more[aria-expanded="true"]) {
		flex-wrap: wrap;
		overflow-x: visible;
	}
	.lmkt-cpf-chips__subcats--scroll .lmkt-cpf-chips__subcats-track {
		flex-wrap: nowrap;
		overflow-x: auto;
	}

	.lmkt-cpf-chips__sorting {
		overflow-x: auto;
		flex-wrap: nowrap;
	}
	.lmkt-cpf-chips__sort {
		flex-shrink: 0;
	}
}
