/**
 * Select Component Styles
 * Переиспользуемые стили для кастомных селектов (dropdowns)
 */

/* Wrapper для кастомного селекта валюты */
.invoice-currency-wrapper {
    position: relative;
    display: block;
    width: 100%;
    height: var(--control-height-md); /* Единая высота контролов */
    overflow: visible !important; /* Разрешаем dropdown выходить за пределы */
    z-index: 1; /* Устанавливаем контекст наложения */
}

/* Когда селект открыт, wrapper должен быть выше календаря */
.invoice-currency-wrapper.select-open {
    z-index: 100001 !important; /* Выше календаря (100000) */
}

/* Скрытое поле для значения */
.invoice-currency-wrapper input[type="hidden"] {
    display: none;
}

/* Кастомный селект - отображение выбранного значения */
.invoice-currency-select {
    background: var(--color-input-bg);
    border: var(--color-input-border);
    border-radius: var(--radius-xl);
    padding: 0 var(--spacing-md);
    font-size: var(--font-size-md);
    color: var(--color-input-text);
    font-family: var(--font-primary);
    transition: all var(--transition-base);
    width: 100%;
    box-sizing: border-box;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    z-index: 2;
    height: var(--control-height-md);
    min-height: var(--control-height-md);
    line-height: var(--control-height-md);
}

.invoice-currency-select:hover {
    background: var(--color-input-bg-hover);
    border: var(--color-input-border);
}

.invoice-currency-wrapper.select-open .invoice-currency-select {
    background: var(--color-input-bg-focus);
    border: var(--color-input-border-focus);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    opacity: 1;
    pointer-events: auto;
    /* Ниже панели списка — иначе при открытии вверх триггер перекрывает опции */
    z-index: 100002;
    position: relative;
    width: 100%;
    box-sizing: border-box;
}

.currency-value {
    flex: 1;
    text-align: left;
}

/* Стрелка в селекте */
.currency-arrow {
    width: 12px;
    height: 8px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1L6 6L11 1' stroke='rgba(255,255,255,0.5)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    transition: transform var(--transition-slow), opacity var(--transition-base), background-image var(--transition-base);
    opacity: 0.6;
    flex-shrink: 0;
    margin-left: var(--spacing-sm);
}

.invoice-currency-select:hover .currency-arrow {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1L6 6L11 1' stroke='rgba(255,255,255,1)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    opacity: 1;
}

.invoice-currency-wrapper.select-open .currency-arrow {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1L6 6L11 1' stroke='rgba(255,255,255,1)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    transform: rotate(180deg);
    opacity: 1;
}

/* Выпадающий список */
.invoice-currency-dropdown {
    position: absolute;
    top: 100%; /* Располагаем dropdown под селектом */
    left: 0;
    right: 0;
    background: var(--color-bg-secondary) !important; /* Непрозрачный фон */
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    visibility: hidden;
    transition: max-height var(--transition-slow), opacity var(--transition-base), visibility var(--transition-base);
    z-index: 100001; /* Выше календаря (100000) для отображения поверх всего */
    display: flex;
    flex-direction: column;
    width: 100%;
    box-sizing: border-box;
    pointer-events: none;
    margin-top: 0; /* Убираем отступ между селектом и dropdown */
}

.invoice-currency-wrapper.select-open .invoice-currency-dropdown {
    opacity: 1;
    visibility: visible;
    max-height: 418px; /* Фиксированная высота dropdown */
    pointer-events: auto;
    background: var(--color-bg-secondary) !important; /* Непрозрачный фон при открытии */
    z-index: 100003; /* Поверх триггера (.invoice-currency-select), особенно при открытии вверх */
}

/* Список открывается вверх, если снизу мало места (логика — financial-mirror.initCurrencyDropdown) */
.invoice-currency-wrapper.dropdown-open-up .invoice-currency-dropdown {
    top: auto;
    bottom: 100%;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.invoice-currency-wrapper.dropdown-open-up.select-open .invoice-currency-select {
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* Внутренний контейнер для скролла */
.invoice-currency-dropdown-inner {
    padding: 2px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    overflow-y: auto;
    overflow-x: hidden;
    width: 100%;
    box-sizing: border-box;
    min-height: 0;
    flex: 1;
    /* Скрыть системный скроллбар */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

/* Кастомный скроллбар внутри скругленного контейнера */
.invoice-currency-dropdown-inner::-webkit-scrollbar {
    width: 6px;
}

.invoice-currency-dropdown-inner::-webkit-scrollbar-track {
    background: transparent;
}

.invoice-currency-dropdown-inner::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.invoice-currency-dropdown-inner::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

.invoice-currency-wrapper.select-open .invoice-currency-dropdown-inner {
    max-height: 100%;
    height: 100%;
    flex: 1;
    min-height: 0;
}

/* Опции в dropdown */
.currency-option {
    background: transparent;
    color: var(--color-text-primary);
    padding: var(--dropdown-option-padding-y) var(--dropdown-option-padding-x);
    font-size: var(--font-size-md);
    font-family: var(--font-primary);
    min-height: 38px;
    line-height: var(--line-height-md);
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    cursor: pointer;
    transition: background var(--transition-base), border-radius var(--transition-base);
    position: relative;
    border-radius: var(--radius-full);
    border: none;
    box-sizing: border-box;
    direction: ltr;
    text-align: left;
}

.currency-option:hover {
    background: var(--color-bg-tertiary);
}

.currency-option.selected {
    background: var(--color-bg-tertiary);
    padding-right: var(--dropdown-option-selected-padding-right);
}

/* Галочка — SVG через mask (ASCII-only в CSS, без UTF-8 в content — иначе «âœ"» при неверной кодировке) */
.currency-option.selected::after {
    content: '';
    position: absolute;
    right: var(--dropdown-check-right);
    left: auto;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    pointer-events: none;
    flex-shrink: 0;
    background-color: currentColor;
    -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z'/%3E%3C/svg%3E");
    mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23000' d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z'/%3E%3C/svg%3E");
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
}

/* Как в invoice-generator: при открытом dropdown выбранная опция не показывается в списке */
.invoice-currency-wrapper.select-open .currency-option.selected {
    display: none !important;
}

/* Hover для селекта обрабатывается через wrapper */
.invoice-currency-wrapper:hover select {
    background: rgba(255, 255, 255, 0.06);
}

/* Light theme: Invoice currency select - same as inputs */
body.light-theme .invoice-currency-select,
html.light .invoice-currency-select,
html.light-theme .invoice-currency-select {
    background: var(--color-input-bg);
    border: var(--color-input-border);
    color: var(--color-input-text);
    transition: background-color var(--transition-base), border-color var(--transition-base);
}

body.light-theme .invoice-currency-select:hover,
html.light .invoice-currency-select:hover,
html.light-theme .invoice-currency-select:hover {
    background: var(--color-input-bg-hover);
    border: var(--color-input-border);
}

body.light-theme .invoice-currency-wrapper.select-open .invoice-currency-select,
html.light .invoice-currency-wrapper.select-open .invoice-currency-select,
html.light-theme .invoice-currency-wrapper.select-open .invoice-currency-select {
    background: var(--color-input-bg-focus);
    border: var(--color-input-border-focus);
}

body.light-theme .currency-arrow,
html.light .currency-arrow,
html.light-theme .currency-arrow {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1L6 6L11 1' stroke='rgba(0,0,0,0.5)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    opacity: 0.6;
}

body.light-theme .invoice-currency-select:hover .currency-arrow,
html.light .invoice-currency-select:hover .currency-arrow,
html.light-theme .invoice-currency-select:hover .currency-arrow {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1L6 6L11 1' stroke='rgba(0,0,0,1)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    opacity: 1;
}

body.light-theme .invoice-currency-wrapper.select-open .currency-arrow,
html.light .invoice-currency-wrapper.select-open .currency-arrow,
html.light-theme .invoice-currency-wrapper.select-open .currency-arrow {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1L6 6L11 1' stroke='rgba(0,0,0,1)' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

body.light-theme .invoice-currency-dropdown,
html.light .invoice-currency-dropdown,
html.light-theme .invoice-currency-dropdown {
    background: var(--color-bg-secondary) !important;
    border: 1px solid var(--color-border-secondary);
    border-top: none;
    box-shadow: var(--shadow-md);
}

body.light-theme .invoice-currency-wrapper.select-open .invoice-currency-dropdown,
html.light .invoice-currency-wrapper.select-open .invoice-currency-dropdown,
html.light-theme .invoice-currency-wrapper.select-open .invoice-currency-dropdown {
    background: var(--color-bg-secondary) !important;
}

body.light-theme .invoice-currency-wrapper.dropdown-open-up .invoice-currency-dropdown,
html.light .invoice-currency-wrapper.dropdown-open-up .invoice-currency-dropdown,
html.light-theme .invoice-currency-wrapper.dropdown-open-up .invoice-currency-dropdown {
    border-top: 1px solid var(--color-border-secondary);
    border-bottom: none;
}

body.light-theme .invoice-currency-dropdown-inner,
html.light .invoice-currency-dropdown-inner,
html.light-theme .invoice-currency-dropdown-inner {
    scrollbar-color: rgba(0, 0, 0, 0.2) transparent;
}

body.light-theme .invoice-currency-dropdown-inner::-webkit-scrollbar-thumb,
html.light .invoice-currency-dropdown-inner::-webkit-scrollbar-thumb,
html.light-theme .invoice-currency-dropdown-inner::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
}

body.light-theme .invoice-currency-dropdown-inner::-webkit-scrollbar-thumb:hover,
html.light .invoice-currency-dropdown-inner::-webkit-scrollbar-thumb:hover,
html.light-theme .invoice-currency-dropdown-inner::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

body.light-theme .currency-option,
html.light .currency-option,
html.light-theme .currency-option {
    color: var(--color-text-inverse);
}

body.light-theme .currency-option:hover,
html.light .currency-option:hover,
html.light-theme .currency-option:hover {
    background: var(--color-bg-primary);
}

body.light-theme .currency-option.selected,
html.light .currency-option.selected,
html.light-theme .currency-option.selected {
    background: var(--color-bg-input);
}

