/* ==========================================================================
 * Kilagbe KMDR -- 1 Taka Khatian search, searchable-combobox UI correction.
 *
 * NEW, ISOLATED FILE. Enqueued only alongside kilagbe-kmdr-book-search.css,
 * on the [kilagbe_kmdr_book_search] page. Adds a custom combobox skin for
 * the five .kmbs-select elements; does not alter kilagbe-kmdr-book-search.css
 * or any other stylesheet.
 *
 * Why a custom skin: a native <select>'s open option list cannot be made to
 * open downward reliably, cannot hold a search input, and always repeats its
 * own placeholder row inside the list -- all three are UI corrections asked
 * for here. The underlying <select> stays in the DOM (visually hidden) as
 * the single source of truth for value and cascading logic; this file only
 * changes how it is PRESENTED and OPERATED.
 * ========================================================================== */

.kmbs-field {
	position: relative;
}

/* The real <select> stays present (for its value, change events, and the
   existing JS that drives cascading/reset/disable), but is visually hidden
   and non-interactive -- the combobox trigger/panel below drive it. */
.kmbs-field[data-kmbs-combobox-ready] > select.kmbs-select {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
	pointer-events: none;
}

.kmbs-combo {
	position: relative;
}

.kmbs-combo-trigger {
	width: 100%;
	min-width: 0;
	font: inherit;
	font-size: 15px;
	text-align: left;
	color: var(--kmbs-ink);
	background: #fff;
	border: 1px solid var(--kmbs-line);
	border-radius: 6px;
	padding: 9px 32px 9px 11px;
	cursor: pointer;
	position: relative;
	background-image: linear-gradient(45deg, transparent 50%, var(--kmbs-muted) 50%), linear-gradient(135deg, var(--kmbs-muted) 50%, transparent 50%);
	background-position: calc(100% - 17px) calc(50% + 2px), calc(100% - 12px) calc(50% + 2px);
	background-size: 5px 5px, 5px 5px;
	background-repeat: no-repeat;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.kmbs-combo-trigger:focus-visible {
	outline: none;
	border-color: var(--kmbs-green);
	box-shadow: 0 0 0 3px rgba(14, 107, 79, 0.12);
}

.kmbs-combo-trigger[aria-disabled="true"] {
	background-color: var(--kmbs-soft);
	color: var(--kmbs-muted);
	cursor: not-allowed;
}

.kmbs-combo-trigger.is-placeholder {
	color: var(--kmbs-muted);
}

.kmbs-combo-panel {
	position: absolute;
	z-index: 40;
	left: 0;
	right: 0;
	top: calc(100% + 4px);
	background: #fff;
	border: 1px solid var(--kmbs-line);
	border-radius: 8px;
	box-shadow: 0 10px 28px rgba(27, 35, 31, 0.14);
	display: none;
	flex-direction: column;
	max-height: 280px;
	overflow: hidden;
}

/* Fallback when there isn't enough room below the trigger (fix #2): the
   controller toggles this class and the panel opens upward instead. */
.kmbs-combo-panel.is-flipped {
	top: auto;
	bottom: calc(100% + 4px);
}

.kmbs-combo.is-open .kmbs-combo-panel {
	display: flex;
}

.kmbs-combo-search {
	flex: 0 0 auto;
	padding: 8px;
	border-bottom: 1px solid var(--kmbs-line);
}

.kmbs-combo-search input {
	width: 100%;
	font: inherit;
	font-size: 14px;
	padding: 7px 9px;
	border: 1px solid var(--kmbs-line);
	border-radius: 5px;
	color: var(--kmbs-ink);
}

.kmbs-combo-search input:focus {
	outline: none;
	border-color: var(--kmbs-green);
	box-shadow: 0 0 0 3px rgba(14, 107, 79, 0.12);
}

.kmbs-combo-list {
	flex: 1 1 auto;
	overflow-y: auto;
	padding: 4px;
	margin: 0;
	list-style: none;
}

.kmbs-combo-option {
	padding: 8px 10px;
	border-radius: 5px;
	font-size: 14px;
	color: var(--kmbs-ink);
	cursor: pointer;
	white-space: normal;
	overflow-wrap: anywhere;
}

.kmbs-combo-option:hover,
.kmbs-combo-option.is-active {
	background: #F1F7F4;
	color: var(--kmbs-green-deep);
}

.kmbs-combo-option[aria-selected="true"] {
	font-weight: 700;
	color: var(--kmbs-green-deep);
}

.kmbs-combo-empty {
	padding: 12px 10px;
	font-size: 13px;
	color: var(--kmbs-muted);
	text-align: center;
}

@media (max-width: 560px) {
	.kmbs-combo-panel {
		max-height: 240px;
	}
}
