/* Shared style language for the designer's rule dialogs.

   The If/Else condition builder established the pattern — a rule is a row that reads left to right
   (subject, test, value), each nesting level states its own join in a "Match ALL / ANY of the
   following" header, and the AND/OR divider between two rows only restates it. The Find Record filter
   dialog reuses the row language so the two editors of "what matches" look the same.
   Both dialogs also depend on `.wf-muted`, so it lives here rather than in one component's scope. */

.wf-muted {
    color: var(--mud-palette-text-secondary);
}

.wf-cb-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.wf-cb-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 10px;
    padding: 10px;
}

.wf-cb-group .wf-cb-group {
    background: var(--mud-palette-action-default-hover);
}

/* ── The level's join: "Match ALL / ANY of the following" ─────────────────────
   One control per level (Notion / HubSpot / Make / n8n / Jira pattern), so the quantifier is always
   visible and editable — including on a level that holds a single condition — and it is obvious which
   level it belongs to. The divider between two rows repeats the word but is not a second control. */
.wf-cb-match {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 28px;
}

    /* A group's header separates the group from its parent's other items. */
    .wf-cb-match--group {
        padding-bottom: 8px;
        border-bottom: 1px solid var(--mud-palette-lines-default);
    }

.wf-cb-match-label {
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--mud-palette-text-primary);
}

.wf-cb-match-toggle {
    display: inline-flex;
    gap: 1px;
    padding: 1px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 7px;
    background: var(--mud-palette-action-default-hover);
}

.wf-cb-match-option {
    border: 0;
    background: transparent;
    color: var(--mud-palette-text-secondary);
    font: inherit;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .06em;
    line-height: 1.5;
    padding: 2px 10px;
    border-radius: 6px;
    cursor: pointer;
}

    .wf-cb-match-option:hover {
        color: var(--mud-palette-text-primary);
    }

    .wf-cb-match-option:focus-visible {
        outline: 2px solid var(--mud-palette-primary);
        outline-offset: 1px;
    }

    .wf-cb-match-option.is-active {
        background: var(--mud-palette-primary);
        color: var(--mud-palette-primary-text);
    }

.wf-cb-match-hint {
    font-size: .78rem;
    color: var(--mud-palette-text-secondary);
}

.wf-cb-match-count {
    margin-left: auto;
    font-size: .7rem;
    color: var(--mud-palette-text-secondary);
}

/* Items stack; the AND/OR pill sits between them and inherits the stack's spacing. */
.wf-cb-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}

/* The join between two items is a single centred label pill — no rule lines either side.
   It restates the level's ALL/ANY choice (the control lives in the header), so it is marked in the
   tertiary accent rather than the primary one the interactive controls use. */
.wf-cb-joiner {
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: stretch;
}

.wf-cb-pill {
    flex: 0 0 auto;
    border: 1px solid var(--mud-palette-tertiary);
    background: var(--mud-palette-tertiary);
    color: var(--mud-palette-tertiary-text);
    font: inherit;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .06em;
    line-height: 1.5;
    padding: 1px 10px;
    border-radius: 999px;
}

/* Passive: the header owns the choice, this only states it. */
.wf-cb-pill--fixed {
    cursor: default;
}

/* Every condition is its own card: the light surface separates two rules that both span the full
   width, which the AND/OR label alone cannot do once the list is long. */
.wf-cb-row {
    display: grid;
    grid-template-columns: minmax(0, 1.7fr) 150px minmax(0, 1fr) auto;
    gap: 8px;
    /* Centre, not start: the outlined fields are taller than the icon buttons beside them. */
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 10px;
    background: var(--mud-palette-background-gray, var(--mud-palette-action-default-hover));
}

/* The source switch governs the value box above it, so it lives in the value column's SECOND grid
   row. Keeping it out of the value cell is what aligns the operator and the row actions with the
   fields: a taller cell would otherwise centre every other item against it. */
.wf-cb-row > .wf-source-switch {
    grid-column: 3;
    grid-row: 2;
    justify-self: end;
    align-self: start;
}

/* Read-only value + the shared data picker button, side by side. */
.wf-cb-pick {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 32px;
    gap: 4px;
    align-items: center;
    min-width: 0;
}

    /* MudBlazor gives a labelled field 8px above + 4px below (space for a helper text these rows never
       have) but an unlabelled editor only 4px above. Normalising all of them keeps every control of a
       row — and every row of the dialog — on the same line, in every value source. The double class is
       deliberate: it out-specifies MudBlazor's own margin utility without !important. */
    .wf-cb-row .mud-input-control.mud-input-control {
        margin: 8px 0 0;
    }

/* The value cell: just the editor — the source switch is a sibling in its own grid row. */
.wf-cb-value {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    min-width: 0;
}

    .wf-cb-value > .mud-input-control {
        flex: 0 0 auto;
    }

    /* A date-and-time value shows a calendar with a clock beside it; the calendar keeps the room
       because that is where the text lives. */
    .wf-cb-value .wf-ve-date > .mud-picker:first-child {
        flex: 1 1 auto;
        min-width: 0;
    }

    .wf-cb-value .wf-ve-date > .mud-picker:last-child {
        flex: 0 0 112px;
    }

/* Script source: the control looks like the input it replaces (same border and 40px height), with the
   action on the left and the script's size on the right — so all three sources occupy one row of the
   same height and the switch below never shifts. */
.wf-cb-script-box {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 40px;
    /* Same top offset as the fields it replaces (see the row's control margin rule). */
    margin-top: 8px;
    padding: 0 12px;
    border: 1px solid var(--mud-palette-lines-inputs);
    border-radius: var(--mud-default-borderradius);
    background: transparent;
    color: var(--mud-palette-text-primary);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

    .wf-cb-script-box:hover:not(:disabled) {
        background: var(--mud-palette-action-default-hover);
    }

    /* Locked until the value being tested is chosen — the switch below it is locked the same way. */
    .wf-cb-script-box:disabled {
        opacity: 0.55;
        cursor: not-allowed;
    }

    .wf-cb-script-box:focus-visible {
        outline: 2px solid var(--mud-palette-primary);
        outline-offset: 1px;
    }

.wf-cb-script-action {
    flex: 0 0 auto;
    font-size: .82rem;
    font-weight: 500;
    color: var(--mud-palette-primary);
}

.wf-cb-script-summary {
    margin-left: auto;
    min-width: 0;
    font-family: var(--wf-mono-font, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
    font-size: .7rem;
    color: var(--mud-palette-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wf-cb-actions {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
}

.wf-cb-actions .mud-icon-button {
    padding: 6px;
    margin: 0;
}

.wf-cb-code {
    font-family: monospace;
    font-size: .74rem;
    word-break: break-all;
}

/* ── Find Record / Find Records: the filter card ───────────────────────────── */

/* The rule is its own card so two adjacent filters never read as one, and so a value that wraps
   stays inside its own boundary. */
.wf-cf-rule {
    padding: 10px;
    background: color-mix(in srgb, var(--mud-palette-surface, #fff) 94%, var(--mud-palette-text-primary, #000));
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 10px;
}

.wf-cf-rule:focus-within {
    border-color: var(--mud-palette-primary);
}

/* Field + test + actions on top, the value underneath: a record field can carry a long id and the
   dialog must not squeeze four controls onto one line to show it. */
.wf-cf-rule-row {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) 170px auto;
    gap: 8px;
    align-items: center;
}

.wf-cf-value-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 32px;
    gap: 4px;
    align-items: start;
    margin-top: 8px;
}

.wf-cf-value-row--plain {
    grid-template-columns: minmax(0, 1fr);
}

.wf-cf-range {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* The summary the panel shows instead of the whole builder. */
.wf-cf-summary {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    background: color-mix(in srgb, var(--mud-palette-surface, #fff) 94%, var(--mud-palette-text-primary, #000));
    border: 1px solid color-mix(in srgb, var(--mud-palette-text-primary, #000) 12%, transparent);
    border-radius: 8px;
}

.wf-cf-summary-line {
    font-size: .78rem;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

/* "Reads as" for an encoded query (ContentQueryOutline): conditions with their joins, one block per
   ^NQ, because a new query block is unioned with the previous ones. */
    .wf-qo {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }

    .wf-qo-empty {
        font-size: .78rem;
        color: var(--mud-palette-text-secondary);
    }

    .wf-qo-block {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
        border: 1px solid var(--mud-palette-lines-default);
        border-radius: 8px;
        padding: 6px 10px;
    }

    /* The join pill sits between two rows, indented so the stack reads as one expression. */
    .wf-qo-join {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 20px;
        font-size: .66rem;
        font-weight: 600;
        letter-spacing: .06em;
        border-radius: 999px;
        padding: 0 8px;
        margin-left: 6px;
        color: var(--mud-palette-text-secondary);
        background: var(--mud-palette-action-default-hover);
    }

    .wf-qo-join--or {
        color: var(--mud-palette-primary);
    }

    .wf-qo-join--block {
        font-size: .7rem;
        color: var(--mud-palette-primary);
        border: 1px solid var(--mud-palette-primary);
        background: transparent;
    }

    .wf-qo-block-join {
        display: flex;
        align-items: center;
        gap: 6px;
        padding-left: 4px;
    }

    .wf-qo-block-join-note,
    .wf-qo-outline-label {
        font-size: .66rem;
        text-transform: uppercase;
        letter-spacing: .06em;
        color: var(--mud-palette-text-secondary);
    }

    .wf-qo-row {
        display: flex;
        align-items: baseline;
        gap: 6px;
        flex-wrap: wrap;
        font-size: .8rem;
        min-width: 0;
    }

    .wf-qo-field {
        font-family: var(--wf-mono-font, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
        font-size: .76rem;
    }

    .wf-qo-test {
        color: var(--mud-palette-text-secondary);
    }

    .wf-qo-value {
        font-family: var(--wf-mono-font, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
        font-size: .74rem;
        background: var(--mud-palette-action-default-hover);
        border-radius: 4px;
        padding: 0 5px;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .wf-qo-sorts {
        display: flex;
        align-items: center;
        gap: 6px;
        flex-wrap: wrap;
        padding-top: 2px;
    }

    .wf-qo-sort {
        font-family: var(--wf-mono-font, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
        font-size: .72rem;
        color: var(--mud-palette-text-secondary);
    }

/* ── Value source switch: Manual / earlier step / script ──────────────────────
   One control for every surface that lets a value come from three places (record field mapping,
   the filter builder, the condition builder). Shared so the switch cannot drift between them. */
.wf-source-switch {
    flex: 0 0 auto;
    display: inline-flex;
    gap: 1px;
    padding: 1px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 6px;
    background: color-mix(in srgb, var(--mud-palette-text-primary) 4%, transparent);
}

.wf-source-option {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--mud-palette-text-secondary);
    cursor: pointer;
}

    .wf-source-option .mud-icon-root {
        font-size: 15px;
    }

    .wf-source-option:hover:not(:disabled) {
        background: var(--mud-palette-action-default-hover);
        color: var(--mud-palette-text-primary);
    }

    .wf-source-option.is-active {
        background: var(--mud-palette-primary);
        color: var(--mud-palette-primary-text);
    }

    .wf-source-option:disabled {
        opacity: 0.4;
        cursor: not-allowed;
    }

    /* An active source stays legible even when it is locked (a stored script for a non-admin). */
    .wf-source-option.is-active:disabled {
        opacity: 1;
    }

    .wf-source-option:focus-visible {
        outline: 2px solid var(--mud-palette-primary);
        outline-offset: 1px;
    }
