/* FarmicleGrow universal select component.
 * Ordinary single-select controls are progressively enhanced by
 * assets/global/js/farmiclegrow-select.js across public + admin + user shells.
 * Existing Select2/Nice Select instances keep their advanced behaviour but
 * receive the same FarmicleGrow visual language. Use data-fg-native-select to
 * explicitly keep a browser-native select.
 */

:root {
    --fg-select-green: #176b45;
    --fg-select-green-strong: #0f5a39;
    --fg-select-lime: #b7ef3a;
    --fg-select-text: #243a2f;
    --fg-select-muted: #718078;
    --fg-select-border: #d4dfd7;
    --fg-select-bg: #fff;
    --fg-select-hover: #f2f8f4;
    --fg-select-selected: #e7f5eb;
    --fg-select-focus: rgba(31, 138, 80, .12);
    --fg-select-shadow: 0 18px 45px rgba(8, 45, 29, .16);
}

select:not([multiple]):not([size]) {
    accent-color: var(--fg-select-green);
}

.fg-select-native {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    margin: -1px !important;
    padding: 0 !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    clip-path: inset(50%) !important;
    border: 0 !important;
    white-space: nowrap !important;
}

.fg-select {
    position: relative;
    width: 100%;
    min-width: 0;
    font: inherit;
}

.fg-select__trigger {
    display: grid;
    width: 100%;
    min-height: 50px;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: 11px 12px 11px 15px;
    border: 1px solid var(--fg-select-border);
    border-radius: 13px;
    color: var(--fg-select-text);
    background: var(--fg-select-bg);
    box-shadow: none;
    font: inherit;
    font-size: inherit;
    line-height: 1.35;
    text-align: left;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

.fg-select__trigger:hover {
    border-color: #afc6b7;
    background: #fcfefc;
}

.fg-select__trigger:focus,
.fg-select__trigger:focus-visible,
.fg-select.is-open .fg-select__trigger,
.fg-select.is-invalid .fg-select__trigger {
    border-color: #4c9d70;
    outline: 0;
    box-shadow: 0 0 0 3px var(--fg-select-focus);
}

.fg-select.is-invalid .fg-select__trigger {
    border-color: #c84e4e;
    box-shadow: 0 0 0 3px rgba(200, 78, 78, .10);
}

.fg-select__trigger-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fg-select__chevron {
    position: relative;
    display: grid;
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    place-items: center;
    border-radius: 8px;
    color: #527063;
    background: #f1f6f2;
    transition: transform .18s ease, background .18s ease, color .18s ease;
}

.fg-select__chevron::before,
.fg-select__chevron::after {
    content: "";
    position: absolute;
    width: 7px;
    height: 1.5px;
    border-radius: 999px;
    background: currentColor;
}

.fg-select__chevron::before { transform: translateX(-2.2px) rotate(45deg); }
.fg-select__chevron::after { transform: translateX(2.2px) rotate(-45deg); }

.fg-select.is-open .fg-select__chevron {
    transform: rotate(180deg);
    color: var(--fg-select-green-strong);
    background: #e4f3e8;
}

.fg-select__menu {
    position: absolute;
    z-index: 1200;
    top: calc(100% + 7px);
    right: 0;
    left: 0;
    max-height: min(300px, 45vh);
    padding: 6px;
    overflow-y: auto;
    overscroll-behavior: contain;
    border: 1px solid #d3dfd6;
    border-radius: 14px;
    background: var(--fg-select-bg);
    box-shadow: var(--fg-select-shadow);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-5px) scale(.995);
    transform-origin: top center;
    transition: opacity .15s ease, transform .15s ease, visibility .15s ease;
    scrollbar-width: thin;
    scrollbar-color: #a8c4b2 transparent;
}

.fg-select.is-open .fg-select__menu {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.fg-select.is-dropup .fg-select__menu {
    top: auto;
    bottom: calc(100% + 7px);
    transform-origin: bottom center;
}

.fg-select__option {
    display: grid;
    width: 100%;
    min-height: 42px;
    grid-template-columns: minmax(0, 1fr) 22px;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    border: 0;
    border-radius: 9px;
    color: #2a4035;
    background: transparent;
    font: inherit;
    font-size: .92em;
    line-height: 1.35;
    text-align: left;
    cursor: pointer;
    transition: color .12s ease, background .12s ease;
}

.fg-select__option:hover,
.fg-select__option:focus-visible,
.fg-select__option.is-active {
    outline: 0;
    color: var(--fg-select-green-strong);
    background: var(--fg-select-hover);
}

.fg-select__option.is-selected {
    color: var(--fg-select-green-strong);
    background: var(--fg-select-selected);
    font-weight: 700;
}

.fg-select__check {
    position: relative;
    display: block;
    width: 18px;
    height: 18px;
    justify-self: end;
    border-radius: 50%;
    opacity: 0;
}

.fg-select__check::before {
    content: "";
    position: absolute;
    top: 4px;
    left: 4px;
    width: 9px;
    height: 5px;
    border-bottom: 2px solid var(--fg-select-green);
    border-left: 2px solid var(--fg-select-green);
    transform: rotate(-45deg);
}

.fg-select__option.is-selected .fg-select__check { opacity: 1; }

.fg-select__option:disabled,
.fg-select__option[aria-disabled="true"] {
    color: #a1aaa4;
    background: transparent;
    cursor: not-allowed;
    opacity: .7;
}

.fg-select.is-disabled .fg-select__trigger,
.fg-select__trigger:disabled {
    color: #969f99;
    border-color: #e0e6e2;
    background: #f4f6f4;
    cursor: not-allowed;
    box-shadow: none;
}

.form-select + .fg-select .fg-select__trigger,
.form-control + .fg-select .fg-select__trigger,
.fg-admin-v2 .fg-select__trigger {
    min-height: 44px;
    border-radius: 10px;
    font-size: .875rem;
}

.fg-admin-v2 .fg-select__menu {
    border-radius: 11px;
    box-shadow: 0 14px 36px rgba(23, 49, 34, .16);
}

/* Universal skin for existing Select2 fields that need search/multi-select. */
.select2-container { width: 100% !important; font: inherit; }
.select2-container .select2-selection--single,
.select2-container .select2-selection--multiple {
    min-height: 50px;
    border: 1px solid var(--fg-select-border) !important;
    border-radius: 13px !important;
    color: var(--fg-select-text);
    background: var(--fg-select-bg) !important;
    box-shadow: none !important;
    transition: border-color .18s ease, box-shadow .18s ease;
}
.select2-container .select2-selection--single .select2-selection__rendered {
    padding: 11px 46px 11px 15px !important;
    color: var(--fg-select-text) !important;
    line-height: 26px !important;
}
.select2-container .select2-selection--single .select2-selection__arrow {
    top: 50% !important;
    right: 11px !important;
    width: 26px !important;
    height: 26px !important;
    border-radius: 8px;
    background: #f1f6f2;
    transform: translateY(-50%);
}
.select2-container .select2-selection--single .select2-selection__arrow b {
    top: 9px !important;
    left: 8px !important;
    margin: 0 !important;
    border-width: 5px 4px 0 !important;
    border-color: #527063 transparent transparent !important;
}
.select2-container--open .select2-selection--single,
.select2-container--focus .select2-selection--single,
.select2-container--focus .select2-selection--multiple {
    border-color: #4c9d70 !important;
    box-shadow: 0 0 0 3px var(--fg-select-focus) !important;
}
.select2-dropdown {
    overflow: hidden;
    border: 1px solid #d3dfd6 !important;
    border-radius: 14px !important;
    background: var(--fg-select-bg) !important;
    box-shadow: var(--fg-select-shadow);
}
.select2-search--dropdown { padding: 8px !important; }
.select2-search--dropdown .select2-search__field {
    min-height: 40px;
    padding: 8px 11px !important;
    border: 1px solid var(--fg-select-border) !important;
    border-radius: 9px;
    outline: 0;
}
.select2-results__options { padding: 5px !important; }
.select2-results__option {
    margin: 1px 0;
    padding: 9px 11px !important;
    border-radius: 9px;
    color: var(--fg-select-text);
    font: inherit;
}
.select2-container--default .select2-results__option--highlighted[aria-selected],
.select2-container--default .select2-results__option--highlighted[data-selected] {
    color: var(--fg-select-green-strong) !important;
    background: var(--fg-select-hover) !important;
}
.select2-container--default .select2-results__option[aria-selected="true"],
.select2-container--default .select2-results__option[data-selected="true"] {
    color: var(--fg-select-green-strong) !important;
    background: var(--fg-select-selected) !important;
    font-weight: 700;
}
.select2-container--default .select2-selection--multiple .select2-selection__choice {
    margin: 6px 3px 3px 3px !important;
    padding: 4px 9px !important;
    border: 0 !important;
    border-radius: 999px !important;
    color: var(--fg-select-green-strong) !important;
    background: var(--fg-select-selected) !important;
}

/* Universal skin for Nice Select instances already used by legacy screens. */
.nice-select {
    width: 100%;
    min-height: 50px;
    height: auto;
    padding: 10px 42px 10px 15px;
    border: 1px solid var(--fg-select-border) !important;
    border-radius: 13px !important;
    color: var(--fg-select-text) !important;
    background: var(--fg-select-bg) !important;
    font: inherit;
    line-height: 28px;
}
.nice-select:after {
    right: 17px !important;
    width: 7px !important;
    height: 7px !important;
    border-color: #527063 !important;
}
.nice-select:focus,
.nice-select.open {
    border-color: #4c9d70 !important;
    box-shadow: 0 0 0 3px var(--fg-select-focus) !important;
}
.nice-select .list {
    width: 100%;
    max-height: 300px;
    padding: 6px;
    overflow-y: auto;
    border: 1px solid #d3dfd6;
    border-radius: 14px !important;
    background: var(--fg-select-bg) !important;
    box-shadow: var(--fg-select-shadow) !important;
}
.nice-select .option {
    min-height: 42px;
    padding: 7px 11px !important;
    border-radius: 9px;
    color: var(--fg-select-text);
    line-height: 28px;
}
.nice-select .option:hover,
.nice-select .option.focus,
.nice-select .option.selected.focus {
    color: var(--fg-select-green-strong) !important;
    background: var(--fg-select-hover) !important;
}
.nice-select .option.selected { font-weight: 700; background: var(--fg-select-selected); }

[data-hs-theme-appearance="dark"] .fg-select,
body.dark .fg-select,
.dark-mode .fg-select {
    --fg-select-text: #edf4ef;
    --fg-select-muted: #aebbb3;
    --fg-select-border: #405049;
    --fg-select-bg: #1e2924;
    --fg-select-hover: #27352f;
    --fg-select-selected: #234332;
    --fg-select-shadow: 0 18px 48px rgba(0, 0, 0, .34);
}

[data-hs-theme-appearance="dark"] .fg-select__chevron,
body.dark .fg-select__chevron,
.dark-mode .fg-select__chevron {
    color: #b4c1b8;
    background: #2d3a34;
}

@media (max-width: 767.98px) {
    .fg-select__menu,
    .nice-select .list { max-height: min(280px, 42vh); }
}

@media (prefers-reduced-motion: reduce) {
    .fg-select__trigger,
    .fg-select__chevron,
    .fg-select__menu,
    .fg-select__option {
        transition: none !important;
    }
}
