/* ------------------------------------------------------------
   Kromeka Select UX — Select2 + native selects
   Uses theme tokens from branding.css (light + dark).
   ------------------------------------------------------------ */

:root {
    --kromeka-select-control-min-height: 44px;
    --kromeka-select-control-padding-y: 8px;
    --kromeka-select-control-padding-x: 12px;
    --kromeka-select-option-padding-y: 11px;
    --kromeka-select-option-padding-x: 12px;
    --kromeka-select-option-line-height: 1.4;
    --kromeka-select-search-min-height: 42px;
    --kromeka-select-dropdown-max-width: 640px;
    --kromeka-select-dropdown-radius: 0.5rem;
    --kromeka-select-dropdown-shadow: 0 0.5rem 1.25rem rgba(0, 0, 0, 0.12);
    --kromeka-select-focus-ring: 0 0 0 0.25rem rgba(245, 181, 31, 0.25);
}

[data-theme="dark"] {
    --kromeka-select-dropdown-shadow: 0 0.75rem 1.5rem rgba(0, 0, 0, 0.45);
}

/* Native selects (opt-out and compact toolbar selects keep their own sizing) */
select.form-control:not(.no-select2):not(.form-control-sm):not(.form-select-sm),
select.form-select:not(.no-select2):not(.form-select-sm) {
    min-height: var(--kromeka-select-control-min-height);
    padding: var(--kromeka-select-control-padding-y) var(--kromeka-select-control-padding-x);
    line-height: var(--kromeka-select-option-line-height);
    background-color: var(--input-bg);
    color: var(--input-text);
    border: 2px solid var(--input-border);
    border-radius: var(--kromeka-select-dropdown-radius);
}

select.form-control:not(.no-select2):not(.form-control-sm):focus,
select.form-select:not(.no-select2):not(.form-select-sm):focus {
    border-color: var(--kromeka-yellow);
    box-shadow: var(--kromeka-select-focus-ring);
    outline: 0;
}

/* Select2 control */
.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple {
    min-height: var(--kromeka-select-control-min-height) !important;
    padding: var(--kromeka-select-control-padding-y) var(--kromeka-select-control-padding-x) !important;
    border-radius: var(--kromeka-select-dropdown-radius) !important;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: calc(var(--kromeka-select-control-min-height) - (var(--kromeka-select-control-padding-y) * 2) - 4px) !important;
    padding-right: 1.75rem !important;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: calc(var(--kromeka-select-control-min-height) - 4px) !important;
    right: 10px !important;
}

.select2-container--default.select2-container--open .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--multiple,
.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--focus .select2-selection--multiple {
    box-shadow: var(--kromeka-select-focus-ring) !important;
}

/* Dropdown panel */
.select2-dropdown.kromeka-select-dropdown,
.kromeka-select-dropdown.select2-dropdown {
    min-width: 100%;
    max-width: min(var(--kromeka-select-dropdown-max-width), calc(100vw - 1.5rem));
    border-radius: var(--kromeka-select-dropdown-radius) !important;
    box-shadow: var(--kromeka-select-dropdown-shadow) !important;
    overflow: hidden;
}

@media (max-width: 575.98px) {
    .select2-dropdown.kromeka-select-dropdown,
    .kromeka-select-dropdown.select2-dropdown {
        max-width: calc(100vw - 1rem);
    }
}

/* Search field inside dropdown */
.select2-container--default .select2-search--dropdown {
    padding: 10px 12px 6px !important;
}

.select2-container--default .select2-search--dropdown .select2-search__field {
    min-height: var(--kromeka-select-search-min-height) !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 10px 12px !important;
    border-radius: calc(var(--kromeka-select-dropdown-radius) - 0.125rem) !important;
    line-height: 1.35 !important;
    box-sizing: border-box !important;
}

.select2-container--default .select2-search--dropdown .select2-search__field:focus {
    box-shadow: var(--kromeka-select-focus-ring) !important;
}

/* Options */
.select2-container--default .select2-results__option {
    padding: var(--kromeka-select-option-padding-y) var(--kromeka-select-option-padding-x) !important;
    line-height: var(--kromeka-select-option-line-height) !important;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] .kromeka-select-option__title,
.select2-container--default .select2-results__option--highlighted[aria-selected] .kromeka-select-option__meta {
    color: #ffffff !important;
}

.select2-container--default .select2-results__option--highlighted[aria-selected] .kromeka-select-option__badge {
    background-color: rgba(255, 255, 255, 0.2) !important;
    color: #ffffff !important;
    border-color: rgba(255, 255, 255, 0.35) !important;
}

/* Rich option layout */
.kromeka-select-option {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.kromeka-select-option__title {
    font-weight: 600;
    color: var(--text-main);
    line-height: var(--kromeka-select-option-line-height);
    word-break: break-word;
}

.kromeka-select-option__meta {
    font-size: 0.875rem;
    color: var(--text-muted);
    line-height: 1.35;
    word-break: break-word;
}

.kromeka-select-option__badge {
    display: inline-block;
    align-self: flex-start;
    margin-top: 0.2rem;
    padding: 0.15rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--text-main);
    background-color: var(--bg-secondary);
    border: 1px solid var(--input-border);
    border-radius: 999px;
}

/* Selected value with rich data — single line in closed control */
.select2-container--default .select2-selection--single .select2-selection__rendered .kromeka-select-option {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.35rem 0.5rem;
}

.select2-container--default .select2-selection--single .select2-selection__rendered .kromeka-select-option__meta {
    font-size: 0.8125rem;
}

.select2-container--default .select2-selection--single .select2-selection__rendered .kromeka-select-option__badge {
    margin-top: 0;
}

/* Keyboard focus visibility */
.select2-container--default .select2-results__option--highlighted[aria-selected] {
    outline: 2px solid var(--kromeka-yellow);
    outline-offset: -2px;
}
