/* ==========================================================================
   Onix LookupField (Components/Shared/LookupField.razor) — a related field:
   an input that searches the records of another model, the list of matches
   and the "Create …" entries under it. js/onix-lookup.js lifts the list
   into the top layer; without popovers it stays the box drawn here under
   the input. Colours, radii and shadows are the tokens of onix-theme.css.
   ========================================================================== */

.lookup { position: relative; display: flex; align-items: center; min-width: 0; width: 100%; }
.lookup .lookup-input { flex: 1 1 auto; min-width: 0; width: 100%; padding-right: 54px; text-overflow: ellipsis; }
.lookup.is-disabled .lookup-input { padding-right: 11px; }
/* "Go to definition" (.lookup-open) is a third control at the input's end — ↗ × ▾; ↗ ▾ without a × (a field a document
   cannot do without); ↗ alone on a disabled field, whether the component disabled it or a disabled fieldset did (the ▾
   is hidden either way: :disabled). */
.lookup.has-open .lookup-input { padding-right: 78px; }
.lookup.has-open:not(:has(.lookup-clear)) .lookup-input { padding-right: 54px; }
.lookup.has-open:has(.lookup-toggle:disabled) .lookup-input { padding-right: 32px; }
.form-card .lookup { margin: 0; }

.lookup-clear, .lookup-toggle, .lookup-open {
    position: absolute; top: 50%; transform: translateY(-50%);
    display: inline-flex; align-items: center; justify-content: center;
    width: 24px; height: 24px; padding: 0;
    border: 0; border-radius: 6px; background: none;
    color: var(--muted); cursor: pointer; font: inherit; line-height: 1; text-decoration: none;
}
.lookup-toggle { right: 4px; }
.lookup-clear { right: 28px; font-size: 1.05rem; }
.lookup-open { right: 52px; }
.lookup:not(:has(.lookup-clear)) .lookup-open { right: 28px; }
.lookup:has(.lookup-toggle:disabled) .lookup-open { right: 4px; }
.lookup-clear:hover, .lookup-toggle:hover, .lookup-open:hover { background: var(--panel-hover); color: var(--ink); }
.lookup-open:hover { color: var(--brand-strong); }
.lookup-open:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--ring); }
.lookup-toggle svg, .lookup-open svg { width: 16px; height: 16px; }
.lookup-toggle svg { transition: transform var(--dur) var(--ease); }
.lookup-open svg { width: 15px; height: 15px; }
.lookup.is-open .lookup-toggle svg { transform: rotate(180deg); }
.lookup-toggle:disabled { display: none; }

/* ─── The list ─────────────────────────────────────────────────────────── */

.lookup-panel {
    position: absolute; inset: auto; left: 0; right: 0; top: calc(100% + 2px); z-index: 130;
    display: flex; flex-direction: column;
    box-sizing: border-box; min-width: 0; max-height: 380px; margin: 0; padding: 4px;
    overflow-y: auto; overscroll-behavior: contain;
    background: var(--glass-pop, var(--panel)); color: var(--ink);
    border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-md);
    font-size: 0.9rem; font-weight: 400; text-align: left; text-transform: none; letter-spacing: normal;
}
.lookup-panel:popover-open { display: flex; animation: pop-in 0.12s var(--ease); }

.lookup-item, .lookup-create {
    display: flex; align-items: baseline; gap: 10px; flex: none;
    width: 100%; box-sizing: border-box; padding: 7px 10px;
    border: 0; border-radius: 8px; background: none;
    color: inherit; font: inherit; text-align: left; text-decoration: none; cursor: pointer;
}
.lookup-item .lookup-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lookup-item .lookup-hint { flex: none; color: var(--muted); font-size: 0.8rem; white-space: nowrap; }
.lookup-item:hover, .lookup-item[data-active], .lookup-create:hover, .lookup-create[data-active] {
    background: var(--panel-hover); color: var(--brand-strong);
}
.lookup-item.is-selected { font-weight: 600; }
.lookup-item.is-selected::after { content: "✓"; flex: none; color: var(--brand); }
.lookup-note { flex: none; padding: 7px 10px; color: var(--muted); font-size: 0.82rem; }
.lookup-error { color: var(--danger); }
.lookup-actions { flex: none; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
.lookup-create { color: var(--brand); font-weight: 550; }
.lookup-create:disabled { color: var(--muted-2); cursor: default; }
.lookup-create .lookup-plus { flex: none; font-weight: 700; }

/* ─── "Create and edit…": a small form in the list's place ─────────────── */

.lookup-form { flex: none; padding: 6px; }
/* The form is taller than a list (REV-018: a partner's is a complete short form); js/onix-lookup.js caps a popover the same way. */
.lookup-panel:has(.lookup-form) { max-height: 640px; }
.lookup-form-title { margin: 2px 4px 10px; font-weight: 650; font-size: 0.92rem; }
.lookup-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 10px; }
.lookup-form-grid .span-2 { grid-column: span 2; }
.lookup-form label { display: block; min-width: 0; margin: 0; }
.lookup-form label > span { display: block; margin-bottom: 3px; font-size: 0.74rem; font-weight: 550; color: var(--ink-soft); }
.lookup-form input, .lookup-form select {
    box-sizing: border-box; width: 100%; height: 32px; margin: 0; padding: 0 8px;
    border: 1px solid var(--line-strong); border-radius: 8px;
    background: var(--panel-2); color: var(--ink); font: inherit; font-size: 0.88rem; box-shadow: none;
}
.lookup-form input:focus, .lookup-form select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 2px var(--ring); }
.lookup-form label.inline { display: flex; align-items: center; gap: 6px; }
.lookup-form label.inline input { width: auto; height: auto; }
.lookup-form label.inline > span { margin: 0; }
.lookup-inline { display: flex; gap: 6px; align-items: center; }
.lookup-inline input { flex: 1 1 auto; }
.lookup-inline .button { flex: none; white-space: nowrap; }
.lookup-form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }

/* Inside an EditGrid cell the field is the cell's editor: the cell's input rules win on padding. */
.edg .dxg-table td .lookup .lookup-input { padding-right: 48px; }
.edg .dxg-table td .lookup.has-open .lookup-input { padding-right: 74px; }
.edg .dxg-table td .lookup.has-open:not(:has(.lookup-clear)) .lookup-input { padding-right: 50px; }
.edg .dxg-table td .lookup.has-open:has(.lookup-toggle:disabled) .lookup-input { padding-right: 28px; }
.edg .dxg-table td .lookup .lookup-clear, .edg .dxg-table td .lookup .lookup-toggle, .edg .dxg-table td .lookup .lookup-open { width: 22px; height: 22px; }
.edg .dxg-table td .lookup .lookup-open { right: 50px; }
.edg .dxg-table td .lookup:not(:has(.lookup-clear)) .lookup-open { right: 26px; }
.edg .dxg-table td .lookup:has(.lookup-toggle:disabled) .lookup-open { right: 3px; }

/* A field in a row of a DataGrid that is edited in place (a stage moved from the list, the journal of a bank
   account): drawn like the EditGrid's editors, since the grid's cells style no input of their own. */
.dxg:not(.edg) .dxg-table td .lookup { min-width: 150px; }
.dxg:not(.edg) .dxg-table td .lookup .lookup-input {
    box-sizing: border-box; width: 100%; height: 32px; margin: 0; padding: 0 48px 0 8px;
    border: 1px solid var(--line-strong); border-radius: 8px;
    background: var(--panel); color: var(--ink); font: inherit; font-size: 0.88rem; box-shadow: none;
}
.dxg:not(.edg) .dxg-table td .lookup .lookup-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 2px var(--ring); }
.dxg:not(.edg) .dxg-table td .lookup.has-open .lookup-input { padding-right: 74px; }
.dxg:not(.edg) .dxg-table td .lookup.has-open:not(:has(.lookup-clear)) .lookup-input { padding-right: 50px; }
.dxg:not(.edg) .dxg-table td .lookup.has-open:has(.lookup-toggle:disabled) .lookup-input { padding-right: 28px; }
.dxg:not(.edg) .dxg-table td .lookup .lookup-clear, .dxg:not(.edg) .dxg-table td .lookup .lookup-toggle, .dxg:not(.edg) .dxg-table td .lookup .lookup-open { width: 22px; height: 22px; }
.dxg:not(.edg) .dxg-table td .lookup .lookup-open { right: 50px; }
.dxg:not(.edg) .dxg-table td .lookup:not(:has(.lookup-clear)) .lookup-open { right: 26px; }
.dxg:not(.edg) .dxg-table td .lookup:has(.lookup-toggle:disabled) .lookup-open { right: 3px; }

/* The "Go to definition" popup (js/onix-definition.js), the record drawer (PartnerDrawer) and the "Send" popups
   (InvoiceSendDialog, InvoiceBatchSendPanel) are drawers: Components/Shared/Drawer, css/onix-drawer.css. */

@media print {
    .lookup-panel, .lookup-clear, .lookup-toggle, .lookup-open { display: none !important; }
}
