/* ============================================================
   Lookup — campo de busca server-side para cadastros grandes.
   Visual alinhado com .wf-form-input / .wf-form-select pra se
   integrar a qualquer Field.
   ============================================================ */

.wf-lookup {
    position: relative;
    display: inline-block;
    width: 100%;
    font-family: var(--wf-font);
}

/* Trigger: clicável quando fechado, vira input quando aberto. */
.wf-lookup-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    padding: 0 10px;
    background: var(--wf-surface);
    border: 1px solid var(--wf-border);
    border-radius: var(--wf-radius-md);
    cursor: text;
    transition: border-color 120ms, box-shadow 120ms;
}

.wf-lookup.open .wf-lookup-trigger {
    border-color: var(--wf-brand-accent);
    box-shadow: 0 0 0 3px rgba(77, 163, 255, 0.15);
}

.wf-lookup-trigger:hover:not(.open) {
    border-color: var(--wf-border-strong, var(--wf-border));
}

/* Valor selecionado (estado fechado). */
.wf-lookup-valor {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    color: var(--wf-text);
}

.wf-lookup-valor.placeholder {
    color: var(--wf-text-subtle);
}

/* Input real (estado aberto). */
.wf-lookup-input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    font-family: var(--wf-font);
    font-size: 13px;
    color: var(--wf-text);
}

.wf-lookup-input::placeholder {
    color: var(--wf-text-subtle);
}

/* Badge "Inativo" ao lado do valor selecionado stale. */
.wf-lookup-badge-inativo {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--wf-surface-alt);
    color: var(--wf-text-muted);
    border: 1px solid var(--wf-border);
    flex-shrink: 0;
}

.wf-lookup-trigger.stale .wf-lookup-valor {
    color: var(--wf-text-muted);
}

/* Botão de limpar (X) no canto. */
.wf-lookup-clear {
    width: 22px;
    height: 22px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--wf-text-subtle);
    cursor: pointer;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 100ms;
}

.wf-lookup-clear:hover {
    background: var(--wf-hover);
    color: var(--wf-text);
}

/* Backdrop invisível para capturar click-outside sem listener global. */
.wf-lookup-backdrop {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: transparent;
}

/* Popover com resultados. */
.wf-lookup-popover {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 320px;
    overflow-y: auto;
    z-index: 501;
    background: var(--wf-surface);
    border: 1px solid var(--wf-border);
    border-radius: var(--wf-radius-md);
    box-shadow: var(--wf-shadow-lg);
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.wf-lookup-item {
    padding: 8px 10px;
    border-radius: var(--wf-radius-sm);
    cursor: pointer;
    font-size: 13px;
    color: var(--wf-text);
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: background 80ms;
}

.wf-lookup-item.hover,
.wf-lookup-item:hover {
    background: var(--wf-hover);
}

.wf-lookup-item.ativo {
    background: var(--wf-selected);
}

.wf-lookup-empty {
    padding: 20px 12px;
    text-align: center;
    font-size: 12px;
    color: var(--wf-text-subtle);
}

/* Rodapé que aparece quando o item selecionado está inativo e o usuário está buscando. */
.wf-lookup-stale-hint {
    margin-top: 4px;
    padding: 8px 10px;
    border-top: 1px solid var(--wf-border);
    background: var(--wf-surface-alt);
    font-size: 12px;
    color: var(--wf-text-muted);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border-radius: 0 0 var(--wf-radius-sm) var(--wf-radius-sm);
}

.wf-lookup-stale-badge {
    margin-left: 6px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 1px 5px;
    border-radius: 3px;
    background: var(--wf-surface);
    color: var(--wf-text-muted);
    border: 1px solid var(--wf-border);
}

.wf-lookup-stale-clear {
    font-size: 12px;
    color: var(--wf-brand-accent);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: var(--wf-font);
}

.wf-lookup-stale-clear:hover {
    background: rgba(77, 163, 255, 0.1);
}
