/* ============================================
   SEARCHABLE SELECT - Desplegable con buscador
   Componente común (js/searchableSelect.js).
   Reutiliza las variables de marca declaradas en create-invoice.css
   (--primary-*, --gray-*, --radius-*, --shadow-*), con valores de
   reserva por si la hoja se carga en una página que no las define.
   ============================================ */

.ss-wrap {
    position: relative;
    width: 100%;
}

/* El <select> original sigue en el DOM (es quien guarda el valor y dispara
   los 'change'), pero no se ve ni se puede pulsar. */
.ss-wrap select.ss-native {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    pointer-events: none;
    z-index: -1;
}

/* La caja de texto hereda las clases del select original
   (.form-control-modern), así que solo se ajusta lo propio del buscador. */
.ss-wrap .ss-input {
    position: relative;
    z-index: 1;
    padding-right: 44px;          /* hueco para la flecha / la "x" */
    text-overflow: ellipsis;
    cursor: pointer;
}

.ss-wrap.is-open .ss-input {
    cursor: text;
}

.ss-wrap .ss-input::placeholder {
    color: var(--gray-400, #9ca3af);
    font-weight: 400;
}

.ss-wrap .ss-input:disabled {
    background: var(--gray-50, #f9fafb);
    color: var(--gray-400, #9ca3af);
    cursor: not-allowed;
}

/* Flecha: mismo dibujo que el select nativo del formulario */
.ss-wrap .ss-caret {
    position: absolute;
    top: 50%;
    right: 12px;
    width: 20px;
    height: 20px;
    margin-top: -10px;
    z-index: 2;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    transition: transform var(--transition-fast, 150ms ease);
}

.ss-wrap.is-open .ss-caret {
    transform: rotate(180deg);
}

.ss-wrap.is-disabled .ss-caret {
    opacity: .4;
    cursor: not-allowed;
}

/* Botón de limpiar: solo aparece cuando hay algo elegido y el ratón
   está sobre el campo, para no competir con la flecha. */
.ss-wrap .ss-clear {
    position: absolute;
    top: 50%;
    right: 10px;
    width: 24px;
    height: 24px;
    margin-top: -12px;
    z-index: 3;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-size: 18px;
    line-height: 1;
    color: var(--gray-500, #6b7280);
    background: var(--gray-100, #f3f4f6);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--transition-fast, 150ms ease);
}

.ss-wrap.has-value:hover .ss-clear,
.ss-wrap.has-value.is-open .ss-clear {
    display: flex;
}

.ss-wrap.has-value:hover .ss-caret,
.ss-wrap.has-value.is-open .ss-caret {
    opacity: 0;
}

.ss-wrap.is-disabled .ss-clear {
    display: none !important;
}

.ss-wrap .ss-clear:hover {
    color: var(--gray-800, #1f2937);
    background: var(--gray-200, #e5e7eb);
}

/* ============================================
   PANEL DE RESULTADOS
   Cuelga de <body> con position:fixed y lo coloca el JS, para que no lo
   recorte ninguna tarjeta con overflow ni quede por debajo del wizard.
   ============================================ */
.ss-panel {
    position: fixed;
    z-index: 9999;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 6px;
    background: #fff;
    border: 1.5px solid var(--primary-500, #4caf50);
    border-radius: var(--radius-md, 12px);
    box-shadow: var(--shadow-lg, 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1));
}

.ss-panel[hidden] {
    display: none;
}

.ss-option {
    padding: 8px 12px;
    font-size: 14px;
    line-height: 1.35;
    color: var(--gray-800, #1f2937);
    border-radius: var(--radius-sm, 8px);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Una sola pista visual para ratón y teclado: la fila activa es la que
   Enter seleccionaría, se haya llegado a ella con flechas o con el ratón. */
.ss-option.is-active {
    background: var(--primary-50, #e8f5e9);
    color: var(--primary-900, #1b5e20);
}

.ss-option.is-disabled {
    color: var(--gray-400, #9ca3af);
    cursor: not-allowed;
}

.ss-option .ss-mark {
    padding: 0;
    font-weight: 700;
    color: var(--primary-700, #388e3c);
    background: transparent;
}

.ss-option.is-active .ss-mark {
    color: var(--primary-800, #2e7d32);
}

.ss-empty,
.ss-more {
    padding: 10px 12px;
    font-size: 12.5px;
    color: var(--gray-500, #6b7280);
    text-align: center;
}

.ss-more {
    margin-top: 4px;
    border-top: 1px solid var(--gray-200, #e5e7eb);
}

/* Barra de scroll discreta dentro del panel */
.ss-panel::-webkit-scrollbar {
    width: 8px;
}

.ss-panel::-webkit-scrollbar-thumb {
    background: var(--gray-300, #d1d5db);
    border-radius: 4px;
}

.ss-panel::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400, #9ca3af);
}
