/* ============================================================================
   HODO — Global Chosen beautification (Bootstrap 5 aligned)
   Makes the jQuery Chosen plugin (.chosen-container) match BS5 form-select /
   form-control look & feel after the Bootstrap 3 -> 5 migration.

   Loaded globally from header_bs_latest.php. Selectors are prefixed with
   `body` so the theme reliably wins over the vendor chosen.min.css even when
   individual pages load that vendor file AFTER the shared header.

   BS5 note: older Chosen CSS (≤1.8.2) hides .chosen-drop with deprecated
   `clip: rect(...)`. Modern browsers ignore that, so the search box stays
   visible under the select. We force display/clip-path hide/show here.

   Chosen copies the native <select> className onto .chosen-container, so
   .form-select / .form-control padding and caret leak onto the wrapper and
   push the dropdown away from the trigger. Those styles are stripped below.
   ============================================================================ */

:root {
	--hd-chosen-border: #ced4da;
	--hd-chosen-border-hover: #b6bec6;
	--hd-chosen-focus: #86b7fe;
	--hd-chosen-focus-shadow: rgba(13, 110, 253, 0.25);
	--hd-chosen-text: #212529;
	--hd-chosen-muted: #6c757d;
	--hd-chosen-radius: 0.375rem;
	--hd-chosen-bg: #fff;
	/* Soft, neutral highlight (no bright link-blue) */
	--hd-chosen-hl-bg: #eef2f7;
	--hd-chosen-hl-text: #212529;
	--hd-chosen-selected-bg: #f1f5f9;
}

/* ---------------------------------------------------------------------------
   NATIVE SELECT — hide only after Chosen has rendered its sibling container
   (avoids permanently hiding selects that never call .chosen())
   --------------------------------------------------------------------------- */
body select.chosen-select:has(+ .chosen-container),
body select.chzn-select:has(+ .chosen-container),
body select.form-select.chosen-select:has(+ .chosen-container),
body select.form-select.chzn-select:has(+ .chosen-container) {
	display: none !important;
}

/* Wrapper --------------------------------------------------------------- */
body .chosen-container {
	font-size: 1rem;
	vertical-align: middle;
	position: relative !important;
	display: block;
	max-width: 100%;
	width: 100%;
	height: auto !important;
	min-height: 0 !important;
	max-height: none !important;
	flex: 0 0 auto !important;
	align-self: start !important;
	overflow: visible !important;
}

/*
 * Chosen copies class="form-select form-select-sm ..." onto the wrapper.
 * BS5 then paints padding, border, caret and min-height on the container,
 * so .chosen-drop { top: 100% } sits below a padded box — not the trigger.
 */
body .chosen-container.form-select,
body .chosen-container.form-select-sm,
body .chosen-container.form-select-lg,
body .chosen-container.form-control,
body .chosen-container.form-control-sm,
body .chosen-container.chosen-select,
body .chosen-container.chzn-select {
	padding: 0 !important;
	border: 0 !important;
	background-color: transparent !important;
	background-image: none !important;
	box-shadow: none !important;
	min-height: 0 !important;
	height: auto !important;
	max-height: none !important;
	line-height: inherit !important;
	appearance: none !important;
	-webkit-appearance: none !important;
}

/*
 * Panel cards use overflow:hidden (content-pages.css), which clips / crushes
 * the absolutely positioned Chosen drop so the search box overlaps the trigger.
 * Allow overflow wherever a Chosen lives.
 */
body .hodo-panel-card:has(.chosen-container),
body .hodo-panel-shell:has(.chosen-container),
body .hodo-side-card:has(.chosen-container),
body .hodo-form-group-card:has(.chosen-container),
body .hodo-form-group-body:has(.chosen-container),
body .card:has(.chosen-container),
body .modal-body:has(.chosen-container),
body .hodo-form-field:has(.chosen-container),
body .hodo-form-column:has(.chosen-container) {
	overflow: visible !important;
}
body .hodo-panel-card:has(.chosen-container.chosen-with-drop),
body .hodo-panel-shell:has(.chosen-container.chosen-with-drop),
body .hodo-side-card:has(.chosen-container.chosen-with-drop),
body .hodo-form-group-card:has(.chosen-container.chosen-with-drop),
body .hodo-form-field:has(.chosen-container.chosen-with-drop) {
	position: relative;
	z-index: 40;
}

/* ---------------------------------------------------------------------------
   KILL the legacy sprite images.
   The vendor chosen.css re-applies chosen-sprite@2x.png with !important inside
   a retina @media query, so on Mac / high-DPI screens the whole sprite strip
   (arrows, ✕, magnifier) bleeds through search boxes and clear buttons.
   These rules (body prefix + !important) override that on every DPI.
   --------------------------------------------------------------------------- */
body .chosen-container-single .chosen-single abbr,
body .chosen-container-single .chosen-single div b,
body .chosen-container-single .chosen-search input[type="text"],
body .chosen-container-single .chosen-search-input input[type="text"],
body .chosen-container-multi .chosen-choices .search-choice-close,
body .chosen-container .chosen-results-scroll-down span,
body .chosen-container .chosen-results-scroll-up span {
	background-image: none !important;
}

/* ---------------------------------------------------------------------------
   SINGLE SELECT
   --------------------------------------------------------------------------- */
body .chosen-container-single .chosen-single {
	display: flex;
	align-items: center;
	min-height: calc(1.5em + 0.75rem + 2px);
	height: auto;
	padding: 0.375rem 2.25rem 0.375rem 0.75rem;
	background: var(--hd-chosen-bg);
	border: 1px solid var(--hd-chosen-border);
	border-radius: var(--hd-chosen-radius);
	box-shadow: none;
	color: var(--hd-chosen-text);
	line-height: 1.5;
	transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}
body .chosen-container-single .chosen-single:hover {
	border-color: var(--hd-chosen-border-hover);
}
body .chosen-container-single .chosen-single span,
body .chosen-container-single .chosen-single span a {
	margin-right: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	color: #495057 !important;
	font-weight: 400 !important;
	text-decoration: none !important;
}
/* Placeholder (default / empty) text stays muted */
body .chosen-container-single .chosen-single.chosen-default span {
	color: var(--hd-chosen-muted) !important;
}
body .chosen-container-single .chosen-single abbr {
	top: 50%;
	transform: translateY(-50%);
	right: 1.9rem;
	width: 0.85rem;
	height: 0.85rem;
	text-align: center;
}
body .chosen-container-single .chosen-single abbr::before {
	content: "\00d7";
	display: block;
	font-size: 0.9rem;
	line-height: 0.85rem;
	color: var(--hd-chosen-muted);
}
body .chosen-container-single .chosen-single abbr:hover::before {
	color: #dc3545;
}

/* Replace the legacy sprite arrow with a Bootstrap-style caret */
body .chosen-container-single .chosen-single div {
	width: 2.25rem;
	top: 0;
	right: 0;
	bottom: 0;
	height: auto;
}
body .chosen-container-single .chosen-single div b {
	display: block;
	width: 100%;
	height: 100%;
	background: none !important;
	position: relative;
	margin: 0 !important;
}
body .chosen-container-single .chosen-single div b::after {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 0.7rem;
	height: 0.7rem;
	transform: translate(-50%, -50%);
	background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
	background-repeat: no-repeat;
	background-position: center;
	background-size: 0.7rem;
}

/* Focus / open state — keep the trigger as the field; menu floats below */
body .chosen-container-active .chosen-single,
body .chosen-container-active.chosen-with-drop .chosen-single {
	border-color: var(--hd-chosen-focus);
	box-shadow: 0 0 0 0.25rem var(--hd-chosen-focus-shadow);
	background: var(--hd-chosen-bg);
	border-radius: var(--hd-chosen-radius);
}

/* ---------------------------------------------------------------------------
   DROPDOWN PANEL
   Permanent hide/show: display + clip-path (clip:rect alone is broken in
   Chromium/Firefox after the BS5 / modern-browser migration).
   Pin to the trigger (container is fit-content), one card for search+results.
   --------------------------------------------------------------------------- */
body .chosen-container .chosen-drop {
	display: none !important;
	visibility: hidden !important;
	pointer-events: none !important;
	position: absolute !important;
	top: 100% !important;
	bottom: auto !important;
	left: 0 !important;
	right: auto !important;
	width: 100% !important;
	height: auto !important;
	min-height: 0 !important;
	max-height: none !important;
	margin: 0.2rem 0 0 !important;
	padding: 0 !important;
	background: var(--hd-chosen-bg) !important;
	border: 1px solid var(--hd-chosen-border) !important;
	border-radius: var(--hd-chosen-radius) !important;
	box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.12);
	overflow: hidden;
	box-sizing: border-box !important;
	clip: rect(0, 0, 0, 0) !important;
	-webkit-clip-path: inset(100% 100%) !important;
	clip-path: inset(100% 100%) !important;
	z-index: 1060;
}
body .chosen-container.chosen-with-drop .chosen-drop {
	display: block !important;
	visibility: visible !important;
	pointer-events: auto !important;
	clip: auto !important;
	-webkit-clip-path: none !important;
	clip-path: none !important;
}
body .chosen-container.chosen-with-drop {
	z-index: 1060;
}

/* Search + results share the same inset so they read as one panel */
body .chosen-container-single .chosen-search {
	padding: 0.4rem 0.4rem 0.25rem !important;
	margin: 0 !important;
	position: relative;
	z-index: 1;
}
body .chosen-container-single .chosen-search input[type="text"] {
	box-sizing: border-box !important;
	width: 100% !important;
	max-width: 100% !important;
	margin: 0 !important;
	padding: 0.35rem 2rem 0.35rem 0.625rem !important;
	border: 1px solid var(--hd-chosen-border) !important;
	border-radius: var(--hd-chosen-radius) !important;
	background: #fff !important;
	background-image: none !important;
	font-size: 0.9375rem;
	line-height: 1.5;
	color: var(--hd-chosen-text);
	box-shadow: none !important;
	outline: none !important;
}
body .chosen-container-single .chosen-search input[type="text"]:focus {
	border-color: var(--hd-chosen-focus) !important;
	box-shadow: none !important;
}
body .chosen-container-single .chosen-search::after {
	content: "";
	position: absolute;
	right: 0.85rem;
	top: calc(0.4rem + 0.55rem);
	width: 0.85rem;
	height: 0.85rem;
	background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%236c757d' stroke-width='1.6' stroke-linecap='round'%3e%3ccircle cx='7' cy='7' r='4.5'/%3e%3cpath d='M10.5 10.5L14 14'/%3e%3c/svg%3e");
	background-repeat: no-repeat;
	background-position: center;
	background-size: contain;
	pointer-events: none;
}

/* ---------------------------------------------------------------------------
   RESULTS LIST
   --------------------------------------------------------------------------- */
body .chosen-container .chosen-results {
	margin: 0 0.4rem 0.4rem !important;
	padding: 0 !important;
	max-height: 260px;
	color: var(--hd-chosen-text);
	background: transparent !important;
	scrollbar-width: thin;
}
body .chosen-container .chosen-results li {
	padding: 0.45rem 0.65rem;
	border-radius: 0.3rem;
	line-height: 1.4;
	font-size: 0.9375rem;
	color: var(--hd-chosen-text);
}
/* Soft neutral highlight (no bright blue link colour) */
body .chosen-container .chosen-results li.highlighted {
	background: var(--hd-chosen-hl-bg);
	background-image: none;
	color: var(--hd-chosen-hl-text);
}
body .chosen-container .chosen-results li.result-selected {
	background: var(--hd-chosen-selected-bg);
	color: var(--hd-chosen-text);
	font-weight: 600;
}
body .chosen-container .chosen-results li.result-selected.highlighted {
	background: var(--hd-chosen-hl-bg);
	color: var(--hd-chosen-hl-text);
}
body .chosen-container .chosen-results li.no-results {
	background: #fff5f5;
	color: #b91c1c;
	border-radius: 0.3rem;
}
body .chosen-container .chosen-results li.group-result {
	font-weight: 700;
	color: var(--hd-chosen-muted);
	text-transform: uppercase;
	font-size: 0.75rem;
	letter-spacing: 0.03em;
}

/* ---------------------------------------------------------------------------
   MULTI SELECT
   --------------------------------------------------------------------------- */
body .chosen-container-multi .chosen-choices {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 0.25rem;
	min-height: calc(1.5em + 0.75rem + 2px);
	padding: 0.25rem 0.5rem;
	background: var(--hd-chosen-bg);
	border: 1px solid var(--hd-chosen-border);
	border-radius: var(--hd-chosen-radius);
	box-shadow: none;
}
body .chosen-container-multi.chosen-container-active .chosen-choices {
	border-color: var(--hd-chosen-focus);
	box-shadow: 0 0 0 0.25rem var(--hd-chosen-focus-shadow);
}
body .chosen-container-multi .chosen-choices li.search-field input[type="text"] {
	height: auto;
	padding: 0.25rem 0;
	color: var(--hd-chosen-text);
	font-size: 0.9375rem;
	line-height: 1.5;
}
body .chosen-container-multi .chosen-choices li.search-choice {
	margin: 0;
	padding: 0.2rem 1.5rem 0.2rem 0.55rem;
	background: #eef2f7;
	background-image: none;
	border: 1px solid #dbe3ec;
	border-radius: 999px;
	box-shadow: none;
	color: #334155;
	font-size: 0.8125rem;
	line-height: 1.4;
}
body .chosen-container-multi .chosen-choices li.search-choice .search-choice-close {
	top: 50%;
	right: 0.5rem;
	transform: translateY(-50%);
	background: none;
}
body .chosen-container-multi .chosen-choices li.search-choice .search-choice-close::before {
	content: "\00d7";
	color: #334155;
	font-size: 0.95rem;
	line-height: 1;
}

/* ---------------------------------------------------------------------------
   DISABLED
   --------------------------------------------------------------------------- */
body .chosen-container.chosen-disabled {
	opacity: 1;
}
body .chosen-container.chosen-disabled .chosen-single,
body .chosen-container.chosen-disabled .chosen-choices {
	background: #e9ecef;
	border-color: var(--hd-chosen-border);
	color: var(--hd-chosen-muted);
	cursor: not-allowed;
}

/* ---------------------------------------------------------------------------
   SIZE VARIANT — when the underlying select is form-select-sm / input-sm
   --------------------------------------------------------------------------- */
body .chosen-container.form-select-sm .chosen-single,
body .hd-chosen-sm .chosen-single {
	min-height: calc(1.5em + 0.5rem + 2px);
	padding: 0.25rem 2rem 0.25rem 0.5rem;
	font-size: 0.875rem;
}
