/* Convención del patrón "enhance": el <select> nativo se conserva en el DOM como
   campo real del form pero se oculta (clase .ic-native-hidden) mientras el shell
   .ui-select hace de UI. Definido aquí (global) para que aplique en cualquier vista,
   no solo en las que lo scopean por módulo. */
.ic-native-hidden { display: none !important; }

.ui-select {
    position: relative;
    display: block;
    min-width: 0;
    color: var(--ui-text, #111827);
    font-family: var(--app-font-family, inherit);
}

.ui-select,
.ui-select *,
.ui-select__popup,
.ui-select__popup * {
    box-sizing: border-box;
}

.ui-select__trigger {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    min-height: 42px;
    margin: 0;
    padding: 8px 12px;
    border: 1px solid var(--ui-border, #e5e7eb);
    border-radius: 9px;
    background: var(--ui-input-bg, #fff);
    color: var(--ui-text, #111827);
    font: inherit;
    font-size: 13px;
    line-height: 1.25;
    text-align: left;
    cursor: pointer;
    transition: border-color .14s ease, box-shadow .14s ease, background .14s ease;
}

.ui-select__trigger:hover {
    border-color: var(--ui-border-strong, #d1d5db);
}

.ui-select__trigger:focus {
    outline: none;
    border-color: var(--ui-accent, #ff6b00);
    box-shadow: var(--ui-focus-ring, 0 0 0 3px rgba(255, 107, 0, .14));
}

.ui-select.is-open .ui-select__trigger {
    border-color: var(--ui-accent, #ff6b00);
}

.ui-select.is-disabled .ui-select__trigger,
.ui-select__trigger:disabled {
    background: var(--ui-surface-soft, #f9fafb);
    color: var(--ui-text-muted, #9ca3af);
    cursor: not-allowed;
    opacity: .72;
}

.ui-select__leading {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    color: var(--ui-accent, #ff6b00);
}

.ui-select__value {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ui-select.is-placeholder .ui-select__value {
    color: var(--ui-text-muted, #9ca3af);
    font-weight: 400;
}

.ui-select__indicator {
    flex: 0 0 auto;
    width: 7px;
    height: 7px;
    margin: -3px 2px 0 4px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    color: var(--ui-text-secondary, #4b5563);
    transform: rotate(45deg);
    transition: transform .14s ease, margin .14s ease;
}

.ui-select.is-open .ui-select__indicator {
    margin-top: 3px;
    transform: rotate(225deg);
}

.ui-select--context {
    display: inline-block;
    max-width: 100%;
}

.ui-select--context .ui-select__trigger {
    min-height: 40px;
    padding: 7px 12px;
    border-radius: 12px;
    background: var(--ui-surface, #fff);
    box-shadow: var(--ui-shadow-soft, 0 1px 2px rgba(0, 0, 0, .05));
    font-size: 12.5px;
    font-weight: 700;
}

.ui-select__popup {
    min-width: 190px;
    margin: 0;
    padding: 6px;
    overflow-x: hidden;
    overflow-y: auto;
    border: 1px solid var(--ui-border, #e5e7eb);
    border-radius: 10px;
    background: var(--ui-surface, #fff);
    color: var(--ui-text, #111827);
    box-shadow: var(--ui-shadow-card, 0 10px 25px rgba(15, 23, 42, .12));
    scrollbar-width: thin;
}

.ui-select__popup[hidden] {
    display: none;
}

.ui-select__popup--searchable {
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}

.ui-select__search {
    position: relative;
    flex: 0 0 auto;
    padding: 8px;
    border-bottom: 1px solid var(--ui-border, #e5e7eb);
    background: var(--ui-surface, #fff);
}

.ui-select__search::before {
    position: absolute;
    z-index: 1;
    top: 19px;
    left: 19px;
    width: 10px;
    height: 10px;
    border: 1.5px solid var(--ui-text-muted, #9ca3af);
    border-radius: 50%;
    content: '';
    pointer-events: none;
}

.ui-select__search::after {
    position: absolute;
    z-index: 1;
    top: 29px;
    left: 29px;
    width: 6px;
    height: 1.5px;
    background: var(--ui-text-muted, #9ca3af);
    content: '';
    pointer-events: none;
    transform: rotate(45deg);
    transform-origin: left center;
}

.ui-select__search-input {
    display: block;
    width: 100%;
    min-height: 38px;
    margin: 0;
    padding: 8px 10px 8px 32px;
    border: 1px solid var(--ui-border, #e5e7eb);
    border-radius: 8px;
    outline: none;
    background: var(--ui-input-bg, #fff);
    color: var(--ui-text, #111827);
    font: inherit;
    font-size: 14px;
    -webkit-appearance: none;
    appearance: none;
}

.ui-select__search-input:focus {
    border-color: var(--ui-accent, #ff6b00);
    box-shadow: var(--ui-focus-ring, 0 0 0 3px rgba(255, 107, 0, .14));
}

.ui-select__search-input::placeholder {
    color: var(--ui-text-muted, #9ca3af);
    opacity: 1;
}

.ui-select__search-input::-webkit-search-cancel-button {
    cursor: pointer;
}

.ui-select__options {
    min-height: 0;
    padding: 6px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.ui-select__status {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-height: 58px;
    padding: 14px 12px;
    color: var(--ui-text-muted, #9ca3af);
    font-size: 13px;
    text-align: center;
}

.ui-select__status[hidden],
.ui-select__options[hidden] {
    display: none;
}

.ui-select__status--loading::before {
    width: 16px;
    height: 16px;
    border: 2px solid var(--ui-border, #e5e7eb);
    border-top-color: var(--ui-accent, #ff6b00);
    border-radius: 50%;
    content: '';
    animation: ui-select-spin .7s linear infinite;
}

.ui-select__status--error {
    color: var(--ui-danger, #ef4444);
}

.ui-select__retry {
    min-height: 34px;
    padding: 6px 12px;
    border: 1px solid var(--ui-accent, #ff6b00);
    border-radius: 8px;
    background: transparent;
    color: var(--ui-accent, #ff6b00);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.ui-select__retry:focus {
    outline: none;
    box-shadow: var(--ui-focus-ring, 0 0 0 3px rgba(255, 107, 0, .14));
}

.ui-select__popup:focus {
    outline: none;
}

.ui-select__option {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 36px;
    padding: 8px 10px;
    border-radius: 7px;
    color: var(--ui-text, #111827);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.25;
    cursor: pointer;
    user-select: none;
}

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

/* Opción de dos líneas: etiqueta principal + sublínea (p.ej. RUC). */
.ui-select__option-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    gap: 1px;
}
.ui-select__option-sub {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    font-weight: 500;
    color: var(--ui-text-muted, #9ca3af);
}

.ui-select__option.is-active,
.ui-select__option:hover {
    background: var(--ui-surface-soft, #f9fafb);
}

.ui-select__option.is-selected {
    background: var(--ui-accent-soft, #fff3eb);
    color: var(--ui-accent, #ff6b00);
}

.ui-select__option.is-active.is-selected {
    box-shadow: inset 0 0 0 1px var(--ui-accent, #ff6b00);
}

.ui-select__option.is-disabled {
    color: var(--ui-text-muted, #9ca3af);
    cursor: not-allowed;
    opacity: .62;
}

.ui-select__option.is-disabled:hover {
    background: transparent;
}

.ui-select__empty {
    padding: 12px 10px;
    color: var(--ui-text-muted, #9ca3af);
    font-size: 13px;
    text-align: center;
}

.ui-select__field-label {
    display: block;
    margin-bottom: 5px;
    color: var(--ui-text-secondary, #4b5563);
    font-size: 12px;
    font-weight: 700;
}

.ui-select__message {
    display: block;
    min-height: 0;
    margin-top: 5px;
    color: var(--ui-danger, #ef4444);
    font-size: 12px;
}

.ui-select.is-invalid .ui-select__trigger {
    border-color: var(--ui-danger, #ef4444);
}

.ui-select.is-loading .ui-select__indicator {
    width: 14px;
    height: 14px;
    margin: 0;
    border: 2px solid var(--ui-border, #e5e7eb);
    border-top-color: var(--ui-accent, #ff6b00);
    border-radius: 50%;
    transform: none;
    animation: ui-select-spin .7s linear infinite;
}

.ui-select--multiple .ui-select__trigger {
    min-height: 42px;
}

.ui-select--multiple .ui-select__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 7px;
}

.ui-select--multiple .ui-select__chips[hidden],
.ui-select--multiple .ui-select__limit[hidden] {
    display: none;
}

.ui-select--multiple .ui-select__chip {
    display: inline-flex;
    max-width: 100%;
    min-height: 30px;
    align-items: center;
    gap: 7px;
    margin: 0;
    padding: 5px 8px 5px 10px;
    border: 1px solid var(--ui-border, #e5e7eb);
    border-radius: 999px;
    background: var(--ui-accent-soft, #fff3eb);
    color: var(--ui-text, #111827);
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    cursor: pointer;
}

.ui-select--multiple .ui-select__chip:hover {
    border-color: var(--ui-accent, #ff6b00);
}

.ui-select--multiple .ui-select__chip:focus {
    outline: none;
    box-shadow: var(--ui-focus-ring, 0 0 0 3px rgba(255, 107, 0, .14));
}

.ui-select--multiple .ui-select__chip:disabled {
    cursor: not-allowed;
    opacity: .62;
}

.ui-select--multiple .ui-select__chip-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ui-select--multiple .ui-select__chip-remove {
    flex: 0 0 auto;
    color: var(--ui-accent, #ff6b00);
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
}

.ui-select--multiple .ui-select__limit {
    margin-top: 6px;
    color: var(--ui-danger, #ef4444);
    font-size: 12px;
    font-weight: 600;
}

.ui-select--multiple.is-limit-reached .ui-select__trigger {
    border-color: var(--ui-danger, #ef4444);
}

.ui-select--multiple.ui-select__popup .ui-select__option {
    gap: 9px;
}

.ui-select--multiple.ui-select__popup .ui-select__option.is-selected::after {
    flex: 0 0 auto;
    margin-left: auto;
    content: '✓';
    font-weight: 800;
}

/* Fila "Seleccionar todas" (config selectAll, solo multiple). Va al tope de la
   lista, separada del resto, y usa la misma marca que las opciones: ✓ cuando
   están todas, – cuando solo algunas. Opera sobre lo que deja la búsqueda. */
.ui-select--multiple.ui-select__popup .ui-select__option--all {
    margin-bottom: 4px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--ui-border, #e5e7eb);
    border-radius: 7px 7px 0 0;
    color: var(--ui-text-secondary, #4b5563);
}
.ui-select--multiple.ui-select__popup .ui-select__option--all.is-partial::after,
.ui-select--multiple.ui-select__popup .ui-select__option--all.is-selected::after {
    flex: 0 0 auto;
    margin-left: auto;
    font-weight: 800;
}
.ui-select--multiple.ui-select__popup .ui-select__option--all.is-partial::after {
    content: '–';
}
.ui-select--multiple.ui-select__popup .ui-select__option--all.is-selected {
    color: var(--ui-text, #111827);
}

.ui-select--multiple.ui-select--chips-inside {
    min-height: 42px;
    border: 1px solid var(--ui-border, #e5e7eb);
    border-radius: 9px;
    background: var(--ui-input-bg, #fff);
    transition: border-color .14s ease, box-shadow .14s ease, background .14s ease;
}

.ui-select--multiple.ui-select--chips-inside:hover {
    border-color: var(--ui-border-strong, #d1d5db);
}

.ui-select--multiple.ui-select--chips-inside:focus-within,
.ui-select--multiple.ui-select--chips-inside.is-open {
    border-color: var(--ui-accent, #ff6b00);
    box-shadow: var(--ui-focus-ring, 0 0 0 3px rgba(255, 107, 0, .14));
}

.ui-select--multiple.ui-select--chips-inside .ui-select__trigger {
    border: 0;
    border-radius: inherit;
    background: transparent;
    box-shadow: none;
}

.ui-select--multiple.ui-select--chips-inside:not(.is-placeholder) {
    padding: 6px 42px 6px 8px;
}

.ui-select--multiple.ui-select--chips-inside:not(.is-placeholder) .ui-select__trigger {
    position: absolute;
    z-index: 0;
    inset: 0;
    justify-content: flex-end;
    min-height: 100%;
    padding: 8px 14px;
}

.ui-select--multiple.ui-select--chips-inside:not(.is-placeholder) .ui-select__value {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.ui-select--multiple.ui-select--chips-inside .ui-select__chips {
    position: relative;
    z-index: 1;
    width: 100%;
    margin: 0;
    pointer-events: none;
}

.ui-select--multiple.ui-select--chips-inside .ui-select__chip {
    pointer-events: auto;
}

.ui-select--multiple.ui-select--chips-inside.is-disabled {
    background: var(--ui-surface-soft, #f9fafb);
    color: var(--ui-text-muted, #9ca3af);
    opacity: .72;
}

.ui-select--multiple.ui-select--chips-inside.is-invalid,
.ui-select--multiple.ui-select--chips-inside.is-limit-reached {
    border-color: var(--ui-danger, #ef4444);
}

@keyframes ui-select-spin {
    to { transform: rotate(360deg); }
}

@media (max-width: 768px) {
    .ui-select__trigger {
        min-height: 44px;
    }

    .ui-select__option {
        min-height: 44px;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .ui-select__search-input {
        min-height: 44px;
        font-size: 16px;
    }

    .ui-select__retry {
        min-height: 44px;
    }

    .ui-select--multiple .ui-select__chip {
        min-height: 36px;
    }

    .ui-select--multiple.ui-select--chips-inside {
        min-height: 44px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ui-select__trigger,
    .ui-select__indicator {
        transition: none;
    }
}
