select.custom-select {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
    opacity: 0;
    pointer-events: none;
}

.custom-select-wrapper {
    position: relative;
    width: 100%;
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 12px 40px 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    font-size: 1rem;
    line-height: 1.4;
    color: var(--text-main);
    background: var(--light);
    cursor: pointer;
    text-align: left;
    transition: border-color 0.15s ease;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
}

.custom-select-trigger:hover {
    border-color: var(--text-muted);
}

.custom-select-trigger:focus,
.custom-select-trigger:focus-visible {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
    background: var(--card-bg);
}

.custom-select-wrapper.is-disabled {
    cursor: not-allowed;
}

.custom-select-trigger.is-disabled,
.custom-select-trigger:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.custom-select-trigger.is-disabled:hover,
.custom-select-trigger:disabled:hover {
    border-color: var(--border);
}

.custom-select-arrow {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    pointer-events: none;
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.custom-select-wrapper.open .custom-select-arrow {
    transform: translateY(-50%) rotate(180deg);
}

.custom-select-value {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.custom-select-dropdown {
    position: fixed;
    z-index: var(--z-picker, 20000);
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    max-height: 240px;
    overflow: hidden;
    display: none;
    flex-direction: column;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

/* Отдельный скроллящийся контейнер под опции — шапка с поиском вынесена
   из зоны скролла, а не "прилипает" внутри неё. Так у неё сплошной фон
   от края до края: скроллбар и списочные элементы больше не могут
   выглянуть из-под неё сбоку, как было бы при sticky-позиционировании
   внутри общего скролл-контейнера. */
.custom-select-options {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 4px;
}

.custom-select-dropdown.visible {
    animation: csReveal 0.2s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.custom-select-dropdown.closing {
    animation: csHide 0.13s cubic-bezier(0.4, 0, 0.2, 1) both;
}

@keyframes csReveal {
    0% {
        opacity: 0;
        transform: scaleY(0.85);
    }

    100% {
        opacity: 1;
        transform: scaleY(1);
    }
}

@keyframes csHide {
    0% {
        opacity: 1;
        transform: scaleY(1);
    }

    100% {
        opacity: 0;
        transform: scaleY(0.85);
    }
}

.custom-select-option {
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 8px;
    font-size: 0.95rem;
    line-height: 1.4;
    color: var(--text-main);
    list-style: none;
}

.custom-select-option.highlighted {
    background: rgba(0, 0, 0, 0.04);
}

@media (hover: hover) and (pointer: fine) {
    .custom-select-option:hover {
        background: rgba(0, 0, 0, 0.04);
    }
}

.custom-select-option.selected {
    background: rgba(0, 0, 0, 0.06);
    font-weight: 600;
}

.custom-select-options::-webkit-scrollbar {
    width: 6px;
}

.custom-select-options::-webkit-scrollbar-track {
    background: transparent;
}

.custom-select-options::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

[data-theme="dark"] .custom-select-trigger {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .custom-select-trigger:hover {
    border-color: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .custom-select-trigger:focus,
[data-theme="dark"] .custom-select-trigger:focus-visible {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .custom-select-option.highlighted {
    background: rgba(255, 255, 255, 0.06);
}

@media (hover: hover) and (pointer: fine) {
    [data-theme="dark"] .custom-select-option:hover {
        background: rgba(255, 255, 255, 0.06);
    }
}

[data-theme="dark"] .custom-select-option.selected {
    background: rgba(255, 255, 255, 0.1);
    font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {

    .custom-select-dropdown.visible,
    .custom-select-dropdown.closing {
        animation: none;
    }
}

.custom-select-search {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: var(--font-main);
    font-size: 0.95rem;
    line-height: 1.4;
    color: var(--text-main);
    background: var(--light);
    outline: none;
    transition: border-color 0.15s ease;
}

.custom-select-search:focus {
    border-color: var(--primary);
}

.custom-select-search::placeholder {
    color: var(--text-muted);
}

.custom-select-search-empty {
    padding: 10px 12px;
    color: var(--text-muted);
    font-size: 0.92rem;
    text-align: center;
    list-style: none;
}

[data-theme="dark"] .custom-select-search {
    background: color-mix(in srgb, var(--card-bg), white 6%);
    border-color: rgba(255, 255, 255, 0.12);
    color: var(--text-main);
}

[data-theme="dark"] .custom-select-search:focus {
    border-color: rgba(255, 255, 255, 0.3);
}

.custom-select-option.cs-option-with-icon {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.cs-option-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cs-option-icon {
    flex: none;
    width: auto;
    min-width: 22px;
    text-align: center;
    font-size: 1.05em;
    color: var(--text-muted);
    line-height: 1;
}

.cs-option-icon i {
    font-size: 1em;
}

.custom-select-value .cs-value-icon {
    display: inline-block;
    margin-right: 8px;
    font-size: 1.05em;
    vertical-align: -1px;
}

.custom-select-value .cs-value-icon i {
    font-size: 1em;
}

.cs-iso-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    line-height: 1;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    vertical-align: middle;
}

.custom-select-value .cs-value-icon:has(.cs-iso-badge) {
    margin-right: 4px;
    font-size: 1em;
    vertical-align: 0;
}

.cs-option-icon .cs-iso-badge {
    min-width: 24px;
    padding: 2px 5px;
    border-radius: 5px;
    background: rgba(15, 23, 42, 0.05);
}

[data-theme="dark"] .cs-option-icon .cs-iso-badge {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.68);
}

/* Полноэкранная шторка на мобильных для полей с поиском (валюта, страна,
   тип устройства). Небольшой заякоренный дропдаун на телефоне не годится:
   его позиция зависит от положения триггера, а появление клавиатуры это
   положение постоянно меняет. Шторка не привязана к триггеру, поэтому
   клавиатура на неё не влияет. */
html.cs-sheet-lock,
html.cs-sheet-lock body {
    overflow: hidden;
    overscroll-behavior: none;
    height: 100%;
}

.custom-select-sheet-header {
    flex: none;
    padding: 6px 4px 4px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
}

.cs-sheet-close {
    display: none;
}

.cs-sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-picker, 20000) - 1);
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.24s ease;
    touch-action: none;
}

.cs-sheet-backdrop.visible {
    opacity: 1;
}

.custom-select-dropdown.cs-sheet {
    position: fixed;
    inset: 0;
    z-index: var(--z-picker, 20000);
    max-height: none;
    width: auto;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.custom-select-dropdown.cs-sheet.visible {
    animation: csSheetIn 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.custom-select-dropdown.cs-sheet.closing {
    animation: csSheetOut 0.22s cubic-bezier(0.4, 0, 0.2, 1) both;
}

@keyframes csSheetIn {
    0% {
        opacity: 0.9;
        transform: translateY(100%);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes csSheetOut {
    0% {
        opacity: 1;
        transform: translateY(0);
    }

    100% {
        opacity: 0.9;
        transform: translateY(100%);
    }
}

.custom-select-dropdown.cs-sheet .custom-select-sheet-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: max(env(safe-area-inset-top, 0px), 14px) 16px 12px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    touch-action: none;
}

.custom-select-dropdown.cs-sheet .custom-select-options {
    padding: 0;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.custom-select-dropdown.cs-sheet .custom-select-search {
    margin: 0;
    font-size: 16px;
    padding: 12px 14px;
}

.custom-select-dropdown.cs-sheet .cs-sheet-close {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--light);
    color: var(--text-main);
    cursor: pointer;
}

.custom-select-dropdown.cs-sheet .cs-sheet-close svg {
    width: 18px;
    height: 18px;
}

[data-theme="dark"] .custom-select-dropdown.cs-sheet .cs-sheet-close {
    background: rgba(255, 255, 255, 0.08);
}

.custom-select-dropdown.cs-sheet .custom-select-option {
    margin: 2px 8px;
    padding: 14px 12px;
    font-size: 1rem;
}

.custom-select-dropdown.cs-sheet .custom-select-search-empty {
    padding: 32px 16px;
    font-size: 1rem;
}

@media (prefers-reduced-motion: reduce) {

    .custom-select-dropdown.cs-sheet.visible,
    .custom-select-dropdown.cs-sheet.closing {
        animation: none;
    }
}