/*
    Field finder modal (Cmd/Ctrl+P). Centered overlay over the AppDef; jump to any field.
    Built on the --cx-* form-builder tokens (already light+dark), so no theme-specific
    overrides are needed here — every value tracks the active theme through the token layer.
*/

/*
    z-index ladder (app.css / form-builder-audit.css): cr-drawer backdrop 1040 / panel 1050,
    builder audit overlay 1080, toasts 1090. The finder can open over an open drawer (§12.1),
    so it must sit ABOVE the drawers (else it renders behind the drawer + backdrop) and BELOW
    toasts (which always stay top-most). scrim 1082 / cluster 1085.
*/
.fb-finder-scrim {
    position: fixed;
    inset: 0;
    background: var(--cx-overlay-scrim);
    backdrop-filter: blur(2px);
    z-index: 1082;
}

.fb-finder-cluster {
    position: fixed;
    top: 96px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    z-index: 1085;
    max-width: calc(100vw - 48px);
}

.fb-finder-modal {
    width: 640px;
    max-width: 70vw;
    max-height: calc(100vh - 192px);
    background: var(--cx-surface);
    color: var(--cx-ink);
    border: 1px solid var(--cx-border);
    border-radius: var(--cx-radius-md);
    box-shadow: var(--cx-shadow-popover), 0 24px 80px rgba(20, 22, 30, .28);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── search header ─────────────────────────────────────────────────────── */

.fb-finder-search {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px 12px;
    border-bottom: 1px solid var(--cx-border-faint, var(--cx-border));
    flex-shrink: 0;
}

.fb-finder-search__icon {
    color: var(--cx-ink-subtle);
    display: inline-flex;
}

.fb-finder-search__input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    font-family: var(--cx-font, inherit);
    font-size: 15.5px;
    color: var(--cx-ink-strong);
    padding: 4px 0;
}

.fb-finder-search__input::placeholder {
    color: var(--cx-ink-subtle);
}

/* ── results ───────────────────────────────────────────────────────────── */

.fb-finder-results {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 6px;
}

.fb-finder-group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px 4px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--cx-ink-subtle);
}

.fb-finder-row {
    display: grid;
    grid-template-columns: 32px 1fr;
    column-gap: 12px;
    padding: 8px 10px 9px;
    margin: 1px 0;
    border-radius: var(--cx-radius-sm);
    cursor: pointer;
    background: transparent;
}

.fb-finder-row[data-selected="true"] {
    background: var(--cx-action-soft);
    box-shadow: inset 0 0 0 1px var(--cx-action-border);
}

.fb-finder-row__icon {
    width: 28px;
    height: 28px;
    align-self: start;
    margin-top: 2px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--cx-border);
    border-radius: var(--cx-radius-sm);
    background: var(--cx-surface-sunken);
    color: var(--cx-ink-muted);
}

.fb-finder-row[data-selected="true"] .fb-finder-row__icon {
    background: var(--cx-surface);
    color: var(--cx-action);
}

.fb-finder-row__main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.fb-finder-row__title-line {
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}

.fb-finder-row__title {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--cx-ink-strong);
}

.fb-finder-row__key {
    font-size: 11px;
    color: var(--cx-ink-key);
    background: var(--cx-surface-sunken);
    border: 1px solid var(--cx-border);
    border-radius: var(--cx-radius-xs);
    padding: 0 5px;
    line-height: 16px;
}

.fb-finder-row__crumb {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    font-size: 11px;
    color: var(--cx-ink-subtle);
}

/* Canon PathCrumb rule glyph — a rule-purple mark next to a section/group crumb that carries a
   display rule. */
.fb-finder-row__crumb-seg {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.fb-finder-row__crumb-rule {
    display: inline-flex;
    align-items: center;
    color: var(--cx-rule);
}

/* ── type + metadata filters (canon TypeChipStrip / MetaFilterRow) ──────── */

.fb-finder-filters {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--cx-border-faint, var(--cx-border));
    /* Fixed chrome: never let the flex column squish the pill strip below its content height —
       a squished overflow-x:auto strip sprouts a vertical scrollbar and clips the pills. The
       results area (flex: 1) absorbs the modal's max-height pressure instead. */
    flex-shrink: 0;
}

/* The type strip scrolls horizontally when the ten type chips overflow the modal width. */
.fb-finder-filters--type {
    overflow-x: auto;
}

.fb-finder-filters__label {
    flex: 0 0 auto;
    margin-right: 4px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--cx-ink-subtle);
}

.fb-finder-filters__spacer {
    flex: 1;
}

.fb-finder-filters__clear {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex: 0 0 auto;
    font-size: 11px;
    color: var(--cx-ink-subtle);
    background: transparent;
    border: none;
    cursor: pointer;
}

.fb-finder-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex: 0 0 auto;
    padding: 3px 9px;
    font-size: 11.5px;
    font-weight: 500;
    white-space: nowrap;
    color: var(--cx-ink-muted);
    background: transparent;
    border: 1px solid var(--cx-border);
    border-radius: var(--cx-radius-pill);
    cursor: pointer;
}

.fb-finder-chip.is-active {
    color: var(--cx-action);
    background: var(--cx-action-soft);
    border-color: var(--cx-action-border);
}

.fb-finder-chip__lead {
    display: inline-flex;
    align-items: center;
}

.fb-finder-chip__star {
    color: var(--cx-error);
    font-weight: 700;
    line-height: 1;
}

/* ── per-row flag pills (canon FlagsRow / Flag) ─────────────────────────── */

.fb-finder-flags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 1px;
}

.fb-finder-flag {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 6px;
    font-size: 10.5px;
    color: var(--cx-ink-muted);
    background: var(--cx-surface-sunken);
    border: 1px solid var(--cx-border);
    border-radius: var(--cx-radius-pill);
}

.fb-finder-flag.is-mono {
    font-family: var(--cx-font-mono);
}

.fb-finder-flag.is-error {
    color: var(--cx-error);
    background: var(--cx-error-soft);
    border-color: var(--cx-error-border);
}

.fb-finder-flag.is-rule {
    color: var(--cx-rule);
    background: var(--cx-rule-soft);
    border-color: var(--cx-rule-border);
}

/* Canon EmptyState — search glyph, "No fields match", a filter-aware detail line, and a
   Clear-filters affordance. */
.fb-finder-empty {
    padding: 36px 28px 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--cx-ink-muted);
}

.fb-finder-empty__icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--cx-surface-sunken);
    border: 1px solid var(--cx-border);
    color: var(--cx-ink-subtle);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.fb-finder-empty__title {
    font-size: 14px;
    font-weight: 600;
    color: var(--cx-ink-strong);
}

.fb-finder-empty__detail {
    font-size: 12px;
    text-align: center;
    max-width: 380px;
    line-height: 1.45;
}

.fb-finder-empty__detail strong {
    color: var(--cx-ink-strong);
    font-weight: 600;
}

.fb-finder-empty__clear {
    margin-top: 8px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--cx-action);
    background: var(--cx-action-soft);
    border: 1px solid var(--cx-action-border);
    border-radius: var(--cx-radius-sm);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

/* ── footer ────────────────────────────────────────────────────────────── */

.fb-finder-footer {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 8px 14px;
    background: var(--cx-surface-sunken);
    border-top: 1px solid var(--cx-border-faint, var(--cx-border));
    color: var(--cx-ink-muted);
    font-size: 11px;
    flex-shrink: 0;
}

.fb-finder-hints {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.fb-finder-hint-sep {
    color: var(--cx-ink-faint, var(--cx-ink-subtle));
}

.fb-finder-count {
    margin-left: auto;
}

.fb-finder-kbd {
    font-family: var(--cx-font-mono);
    font-size: 10px;
    color: var(--cx-ink);
    background: var(--cx-surface);
    border: 1px solid var(--cx-border);
    border-radius: var(--cx-radius-xs);
    padding: 0 4px;
    height: 14px;
    line-height: 13px;
    display: inline-flex;
    align-items: center;
}

.fb-finder-mono {
    font-family: var(--cx-font-mono);
}

/* ── peek pane ─────────────────────────────────────────────────────────── */

.fb-finder-peek {
    width: 400px;
    flex: 0 0 auto; /* keep its width and wrap below the modal on narrow viewports rather than squashing */
    max-height: calc(100vh - 192px);
    background: var(--cx-surface);
    color: var(--cx-ink);
    border: 1px solid var(--cx-border);
    border-radius: var(--cx-radius-md);
    box-shadow: var(--cx-shadow-popover), 0 24px 80px rgba(20, 22, 30, .28);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.fb-finder-peek__header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--cx-border-faint, var(--cx-border));
}

.fb-finder-peek__icon {
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--cx-action-border);
    border-radius: var(--cx-radius-sm);
    background: var(--cx-action-soft);
    color: var(--cx-action);
}

.fb-finder-peek__lockup {
    flex: 1;
    min-width: 0;
}

.fb-finder-peek__eyebrow {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--cx-ink-subtle);
}

.fb-finder-peek__title {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--cx-ink-strong);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fb-finder-peek__body {
    overflow-y: auto;
    padding: 4px 0 0;
}

/* Canon PeekSection: an uppercase letterspaced label over a stack of rows, divided by a faint
   rule. Identity / Rules / Constraints / Dependencies. */
.fb-finder-peek__section {
    padding: 10px 14px 12px;
    border-bottom: 1px solid var(--cx-border-faint, var(--cx-border));
}

.fb-finder-peek__section-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--cx-ink-subtle);
    margin-bottom: 6px;
}

.fb-finder-peek__rows {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* Canon PeekRow: 72px label column + value. */
.fb-finder-peek__row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 12px;
}

.fb-finder-peek__row-label {
    flex: 0 0 72px;
    width: 72px;
    color: var(--cx-ink-subtle);
    font-size: 11px;
}

.fb-finder-peek__row-value {
    flex: 1;
    min-width: 0;
    color: var(--cx-ink);
    /* Break a pathologically long unbroken value (e.g. a long field key) rather than overflow
       the 340px pane. Canon doesn't specify this; it's defensive layout-safety only. */
    overflow-wrap: break-word;
}

/* Section breadcrumb, inline in the Identity > Section row value. */
.fb-finder-peek__crumb {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* Canon PeekRuleRow: the slot label stacked above a full-width sentence (display / validation). */
.fb-finder-peek__rule-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.fb-finder-peek__rule-label {
    color: var(--cx-ink-subtle);
    font-size: 11px;
}

/* Canon PeekRuleSentence: a rule-purple pill carrying the rule glyph, the kind prefix
   ("show if" / "hide if" / "validates" / "required if"), and the RuleSentence chips. The pill
   wraps within the pane rather than overflowing the 340px peek; the chips carry their own theming. */
.fb-finder-peek__rule-pill {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
    min-width: 0;
    background: var(--cx-rule-soft);
    border: 1px solid var(--cx-rule-border);
    border-radius: var(--cx-radius-pill);
    padding: 2px 8px;
    font-size: 11px;
}

/* Leading rule glyph — always rule-purple (canon). Scoped here so the purple doesn't bleed onto
   the chips' own ink. */
.fb-finder-peek__rule-glyph {
    display: inline-flex;
    color: var(--cx-rule);
}

/* Kind prefix: muted for validation / required-if; rule-purple for the display slot (canon). */
.fb-finder-peek__rule-prefix {
    font-weight: 600;
    color: var(--cx-ink-muted);
}

.fb-finder-peek__rule-prefix.is-display {
    color: var(--cx-rule);
}

.fb-finder-peek__mono {
    font-family: var(--cx-font-mono);
    font-size: 11.5px;
    color: var(--cx-ink-key);
}

.fb-finder-peek__required {
    color: var(--cx-error);
}

.fb-finder-peek__optional {
    color: var(--cx-ink-muted);
}

.fb-finder-peek__muted {
    color: var(--cx-ink-subtle);
}

.fb-finder-peek__prompt {
    line-height: 1.4;
    color: var(--cx-ink-muted);
}

.fb-finder-peek__refs-count {
    color: var(--cx-ink-strong);
    font-weight: 600;
}

.fb-finder-peek__refs-hint {
    color: var(--cx-ink-subtle);
}

.fb-finder-peek__footer {
    display: flex;
    justify-content: flex-end;
    padding: 8px 12px;
    background: var(--cx-surface-sunken);
    border-top: 1px solid var(--cx-border-faint, var(--cx-border));
}

.fb-finder-peek__jump {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11.5px;
    font-weight: 500;
    color: var(--cx-action);
    background: transparent;
    border: none;
    cursor: pointer;
}
