/* anota form builder chrome (bld-*). Field visuals come from anota-forms.css (af-*).
   Retokened onto the shared var(--an-*) design system (app.css) — this file used to hardcode
   its own near-duplicate, drifting palette (an off-brand primary #21a884 vs the real
   --an-primary #16A385, its own gradient button, its own font stack). Buttons are unified onto
   the app-wide flat an-btn-* style; bld-btn's compact padding is kept as the deliberate "dense"
   size tier for this toolbar-heavy screen, not a separate visual language. */

.bld-root {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--an-slate-50);
    font-family: var(--an-font);
}

/* ---------- top bar ----------
   Three-column grid, not a plain flex row: the outer 1fr columns absorb whatever
   width the title/actions need, so the middle column (the main tabs) stays truly
   centered on the page regardless of title length or how many action buttons are
   present — a flex row with margin-left:auto on the trailing group can't do this,
   it only pushes content to the edges, not center a middle item independently. */
.bld-topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: #ffffff;
    border-bottom: 1px solid var(--an-slate-200);
}

.bld-topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.bld-back {
    font-size: 20px;
    text-decoration: none;
    color: var(--an-slate-600);
    padding: 2px 8px;
    border-radius: 6px;
}

.bld-back:hover { background: var(--an-slate-100); }

.bld-title {
    font-size: 16px;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 6px 10px;
    min-width: 280px;
    background: transparent;
}

.bld-title:hover { border-color: var(--an-slate-200); }
.bld-title:focus { border-color: var(--an-primary); outline: none; background: #fff; }

.bld-topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

/* ---------- main tabs (Build / Settings / Publish) ----------
   Underline-indicator nav, not pill buttons — this is primary navigation between
   the builder's three modes, so it needs more visual weight than a bld-btn action.
   Icons reuse the same monoline SVG language as FieldPalette's field-type icons
   (24x24, stroke=currentColor, stroke-width 2) for one consistent icon system
   across the builder, not a one-off set. */
.bld-main-tabs {
    display: flex;
    gap: 4px;
    align-self: stretch;
}

.bld-main-tab {
    display: flex;
    align-items: center;
    gap: 7px;
    border: none;
    background: transparent;
    padding: 0 14px;
    font-size: 13.5px;
    font-weight: 600;
    letter-spacing: .01em;
    color: var(--an-slate-500);
    cursor: pointer;
    border-bottom: 2.5px solid transparent;
    transition: color .15s ease, border-color .15s ease;
}

.bld-main-tab-icon { width: 15px; height: 15px; flex-shrink: 0; opacity: .85; }

.bld-main-tab:hover { color: var(--an-slate-800); }

.bld-main-tab-active {
    color: var(--an-primary);
    font-weight: 700;
    border-bottom-color: var(--an-primary);
}

.bld-main-tab-active .bld-main-tab-icon { opacity: 1; }

.bld-save-status { font-size: 12.5px; color: var(--an-slate-500); min-width: 60px; text-align: right; }
.bld-save-error { color: var(--an-error); }

.bld-conflict {
    background: #FFF8EB;
    border-bottom: 1px solid #F5D9A8;
    color: var(--an-warning);
    padding: 8px 16px;
    font-size: 14px;
}

/* ---------- buttons ----------
   One visual language (flat fill, tokened colors, 6px radius) shared with an-btn-*; this
   compact size tier stays smaller than an-btn's 10px×22px because the builder toolbar and
   property panel are too dense for the larger padding. */
.bld-btn, .bld-btn-primary, .bld-btn-danger, .bld-btn-small {
    border: 1px solid var(--an-slate-200);
    background: #fff;
    border-radius: 6px;
    padding: 6px 12px;
    font-size: 14px;
    cursor: pointer;
    color: var(--an-slate-600);
    text-decoration: none;
    display: inline-block;
}

.bld-btn:hover:not(:disabled) { background: var(--an-slate-50); }
.bld-btn:disabled { opacity: .4; cursor: default; }

.bld-btn-primary {
    background: var(--an-primary);
    color: #fff;
    border: none;
    font-weight: 600;
    padding: 7px 18px;
}

.bld-btn-primary:hover { background: var(--an-primary-dark); }

.bld-btn-danger { color: var(--an-error); border-color: #F0B9B9; }
.bld-btn-danger:hover { background: var(--an-error); color: #fff; border-color: var(--an-error); }

.bld-btn-small { padding: 4px 10px; font-size: 13px; }

.bld-btn-icon {
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--an-slate-400);
    font-size: 13px;
    padding: 2px 6px;
    border-radius: 4px;
}

.bld-btn-icon:hover { color: var(--an-error); background: #FEF2F2; }

/* ---------- panes ---------- */
.bld-panes {
    display: grid;
    grid-template-columns: 260px 1fr 300px;
    flex: 1;
    min-height: 0;
}

.bld-left, .bld-right {
    background: #fff;
    overflow-y: auto;
    border-right: 1px solid var(--an-slate-200);
}

.bld-right { border-right: none; border-left: 1px solid var(--an-slate-200); }

.bld-canvas-host {
    overflow-y: auto;
    padding: 24px;
}

.bld-right-empty {
    padding: 32px 20px;
    color: var(--an-slate-400);
    font-size: 13.5px;
    text-align: center;
}

/* ---------- Settings / Publish tabs ----------
   Grid, not centered flex: matches .bld-panes's flush-left palette column exactly (260px)
   so the nav rail lines up with the Build tab's field palette instead of floating in the
   middle of the screen. */
.bld-settings-tab, .bld-publish-tab {
    display: grid;
    grid-template-columns: 260px 1fr;
    flex: 1;
    min-height: 0;
}

/* LogicPanel takes over the tab as its own detail view (own "← Volver" back nav) — it's a
   direct child, not part of the nav-rail grid below, so it spans both columns and keeps the
   older centered/capped treatment instead of being squeezed into the 260px nav column. */
.bld-settings-tab > .bld-props {
    grid-column: 1 / -1;
    justify-self: center;
    align-self: flex-start;
    width: min(480px, 100%);
    margin: 24px 16px;
    overflow-y: auto;
}

/* Removes the wrapper from box layout so its nav/content children become direct grid items
   of the 260px-left grid above — same DOM, no markup change needed in ThemePanel.razor or
   Builder.razor's Publish block to line up with the Build tab's palette. */
.bld-settings-layout { display: contents; }

.bld-settings-nav {
    grid-column: 1;
    background: #fff;
    border-right: 1px solid var(--an-slate-200);
    overflow-y: auto;
    padding: 16px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.bld-settings-nav-item {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    border-left: 2.5px solid transparent;
    border-radius: 0 8px 8px 0;
    padding: 9px 30px 9px 14px;
    cursor: pointer;
}

.bld-settings-nav-item:hover { background: var(--an-slate-50); }

.bld-settings-nav-item strong { font-size: 13.5px; font-weight: 600; color: var(--an-slate-700); }
.bld-settings-nav-item small { font-size: 11.5px; color: var(--an-slate-400); }

.bld-settings-nav-active {
    border-left-color: var(--an-primary);
    background: var(--an-primary-subtle);
}

.bld-settings-nav-active strong { color: var(--an-primary-dark); }

.bld-settings-nav-count {
    position: absolute;
    top: 9px;
    right: 10px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--an-slate-100);
    color: var(--an-slate-500);
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bld-settings-nav-active .bld-settings-nav-count { background: var(--an-primary); color: #fff; }

.bld-settings-content {
    grid-column: 2;
    min-width: 0;
    overflow-y: auto;
    padding: 24px 28px;
}

.bld-settings-content > .bld-props { width: min(560px, 100%); }

.bld-publish-prompt {
    grid-column: 1 / -1;
    width: min(480px, 100%);
    text-align: center;
    background: #fff;
    border: 1px solid var(--an-slate-200);
    border-radius: 12px;
    padding: 40px 32px;
    justify-self: center;
    align-self: flex-start;
    margin-top: 40px;
}

.bld-publish-prompt h2 { margin: 0 0 8px; font-size: 18px; color: var(--an-slate-800); }
.bld-publish-prompt p { margin: 0 0 20px; color: var(--an-slate-500); font-size: 14px; }

/* ---------- palette ---------- */
.bld-palette { padding: 12px; }

.bld-palette-search {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--an-slate-200);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 13px;
    color: var(--an-slate-600);
    margin-bottom: 12px;
}

.bld-palette-search:focus { border-color: var(--an-primary); outline: none; }
.bld-palette-search::placeholder { color: var(--an-slate-300); }

.bld-palette-group { margin-bottom: 14px; }

.bld-palette-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--an-slate-400);
    margin: 0 4px 6px;
}

.bld-palette-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border: 1px solid var(--an-slate-200);
    border-radius: 8px;
    margin-bottom: 4px;
    font-size: 13.5px;
    color: var(--an-slate-600);
    cursor: grab;
    background: #fff;
    user-select: none;
}

.bld-palette-item:hover { border-color: var(--an-primary); box-shadow: var(--an-shadow-sm); }
.bld-palette-item:active { cursor: grabbing; }

.bld-palette-icon {
    width: 22px;
    display: flex;
    justify-content: center;
    flex-shrink: 0;
    color: var(--an-primary);
}

.bld-palette-icon svg {
    width: 16px;
    height: 16px;
}

/* ---------- canvas ---------- */
.bld-page {
    max-width: 760px;
    margin: 0 auto 20px;
    background: #fff;
    border-radius: 12px;
    box-shadow: var(--an-shadow-sm);
}

.bld-page-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 12px;
    color: var(--an-slate-400);
    border-bottom: 1px dashed var(--an-slate-200);
}

.bld-canvas {
    position: relative;
    padding: 20px;
    min-height: 120px;
}

.bld-canvas-empty {
    grid-column: span 12;
    border: 2px dashed var(--an-slate-300);
    border-radius: 10px;
    padding: 36px;
    text-align: center;
    color: var(--an-slate-400);
    font-size: 14px;
}

.bld-field {
    position: relative;
    border: 1.5px solid transparent;
    border-radius: 8px;
    padding: 6px;
    cursor: grab;
}

.bld-field:hover { border-color: var(--an-slate-200); }

.bld-field.bld-selected { border-color: var(--an-primary); background: var(--an-primary-subtle); }

.bld-field.bld-dragging { opacity: .4; }

.bld-hidden-badge {
    position: absolute;
    top: 4px;
    right: 6px;
    font-size: 10px;
    background: var(--an-slate-100);
    color: var(--an-slate-500);
    border-radius: 4px;
    padding: 1px 6px;
}

/* completion badge — sits below the hidden badge when both are present */
.bld-i18n-badge {
    position: absolute;
    top: 4px;
    right: 6px;
    font-size: 10px;
    background: var(--an-primary-subtle);
    color: var(--an-primary-dark);
    border-radius: 4px;
    padding: 1px 6px;
}

.bld-hidden-badge + .bld-i18n-badge,
.bld-i18n-badge:has(+ .bld-hidden-badge) { top: 22px; }

/* hover-revealed quick actions — top-left, opposite the always-on badges above */
.bld-field-actions {
    position: absolute;
    top: 4px;
    left: 6px;
    display: flex;
    align-items: center;
    gap: 1px;
    background: #fff;
    border: 1px solid var(--an-slate-200);
    border-radius: 6px;
    padding: 1px;
    opacity: 0;
    transition: opacity .12s;
    z-index: 1;
}

.bld-field:hover .bld-field-actions,
.bld-field.bld-selected .bld-field-actions { opacity: 1; }

.bld-field-grip {
    cursor: grab;
    color: var(--an-slate-400);
    font-size: 12px;
    padding: 2px 5px;
    line-height: 1;
}

/* ---------- language tabs (field/page/settings translation editing) ---------- */
.bld-lang-tabs {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.bld-lang-tab {
    border: 1px solid var(--an-slate-200);
    background: #fff;
    color: var(--an-slate-500);
    border-radius: 6px;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}

.bld-lang-tab:hover { border-color: var(--an-primary); color: var(--an-primary); }

.bld-lang-tab-active {
    background: var(--an-primary);
    border-color: var(--an-primary);
    color: #fff;
}

.bld-lang-primary {
    margin-left: auto;
    font-size: 11px;
    color: var(--an-slate-400);
}

.bld-page-label {
    color: var(--an-slate-400);
    font-size: 12px;
    flex: none;
    white-space: nowrap;
}

.bld-page-title-input {
    flex: 1;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 3px 8px;
    font-size: 12.5px;
    background: transparent;
    color: var(--an-slate-600);
}

.bld-page-title-input:hover { border-color: var(--an-slate-200); }
.bld-page-title-input:focus { border-color: var(--an-primary); outline: none; background: #fff; }
.bld-page-title-input::placeholder { color: var(--an-slate-300); }

.bld-drop-indicator {
    position: absolute;
    left: 12px;
    right: 12px;
    height: 3px;
    background: var(--an-primary);
    border-radius: 2px;
    pointer-events: none;
    z-index: 5;
}

.bld-add-page {
    display: block;
    margin: 0 auto 32px;
    border: 1px dashed var(--an-slate-400);
    background: transparent;
    color: var(--an-slate-500);
    border-radius: 8px;
    padding: 8px 20px;
    cursor: pointer;
    font-size: 13.5px;
}

.bld-add-page:hover { border-color: var(--an-primary); color: var(--an-primary); }

/* ---------- property panel ---------- */
.bld-props { padding: 14px; font-size: 13.5px; }

.bld-props-empty { color: var(--an-slate-400); text-align: center; padding: 40px 10px; }

.bld-props-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.bld-props-type {
    font-weight: 600;
    color: var(--an-ink);
    text-transform: capitalize;
}

/* Groups the field's properties (Content / Validation / Appearance) into distinct cards,
   echoing the bordered-card language of .bld-logic-card and the small-caps section labels
   of .bld-palette-title. */
.bld-prop-group {
    border: 1px solid var(--an-slate-200);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 12px;
    background: #fff;
}

.bld-prop-group-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--an-slate-400);
    margin: 0 0 10px;
}

.bld-prop-group .bld-prop:last-child,
.bld-prop-group .bld-prop-advanced:last-child { margin-bottom: 0; }

.bld-prop { display: block; margin-bottom: 12px; }

.bld-prop > span {
    display: block;
    font-size: 12px;
    color: var(--an-slate-500);
    margin-bottom: 4px;
}

.bld-prop input[type="text"], .bld-prop input:not([type]), .bld-prop input[type="number"],
.bld-prop select, .bld-prop textarea {
    width: 100%;
    border: 1px solid var(--an-slate-200);
    border-radius: 7px;
    padding: 7px 9px;
    font-size: 13.5px;
    background: #fff;
}

.bld-prop input:focus, .bld-prop select:focus, .bld-prop textarea:focus {
    border-color: var(--an-primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(22, 163, 133, .14);
}

.bld-prop-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

.bld-prop-inline > span { margin: 0; font-size: 13.5px; color: var(--an-slate-600); }

/* ---------- notification recipient chip input (Publish > Notificaciones) ---------- */
.bld-chip-input {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--an-slate-200);
    border-radius: 7px;
    padding: 6px 8px;
    background: #fff;
}

.bld-chip-input:focus-within {
    border-color: var(--an-primary);
    box-shadow: 0 0 0 3px rgba(22, 163, 133, .14);
}

.bld-chip-input-error, .bld-chip-input-error:focus-within {
    border-color: var(--an-error);
    box-shadow: 0 0 0 3px rgba(198, 40, 40, .12);
}

.bld-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--an-primary-subtle);
    color: var(--an-primary-dark);
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    padding: 6px 6px 6px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

.bld-chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--an-primary-dark);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    opacity: .7;
}

.bld-chip-remove:hover { opacity: 1; background: rgba(15, 138, 112, .16); }

.bld-chip-input-field {
    flex: 1 1 120px;
    min-width: 120px;
    border: none;
    outline: none;
    font-size: 13.5px;
    padding: 4px 2px;
    background: transparent;
}

.bld-chip-input-hint { font-size: 12px; color: var(--an-slate-400); margin: 5px 0 0; }
.bld-chip-input-hint-error { color: var(--an-error); }

.bld-notif-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 4px;
}

.bld-notif-saved { font-size: 13px; color: var(--an-success); font-weight: 600; }

/* ---------- email settings list + card editor (Publish > Notificaciones) ---------- */
.bld-email-add-row { display: flex; gap: 8px; margin-bottom: 16px; }

.bld-email-list { display: flex; flex-direction: column; gap: 10px; }

.bld-email-card {
    border: 1px solid var(--an-slate-200);
    border-left-width: 4px;
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
}

.bld-email-card-rail-notification { border-left-color: #D97706; }
.bld-email-card-rail-autoresponder { border-left-color: var(--an-primary); }

.bld-email-card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    cursor: pointer;
}

.bld-email-card-type {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
}
.bld-email-card-type-notification { color: #D97706; }
.bld-email-card-type-autoresponder { color: var(--an-primary-dark); }

.bld-email-card-summary {
    flex: 1;
    min-width: 0;
    font-size: 13.5px;
    color: var(--an-slate-600);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bld-email-card-body {
    border-top: 1px solid var(--an-slate-200);
    padding: 16px;
}

.bld-email-tabs {
    display: flex;
    gap: 16px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--an-slate-200);
}

.bld-email-tab {
    border: none;
    background: none;
    padding: 8px 2px;
    font-size: 13px;
    font-weight: 600;
    color: var(--an-slate-400);
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.bld-email-tab-active {
    color: var(--an-primary-dark);
    border-bottom-color: var(--an-primary);
}

.bld-email-body-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.bld-email-insert-field {
    font-size: 12px;
    padding: 4px 8px;
    border: 1px solid var(--an-slate-200);
    border-radius: 6px;
    background: #fff;
    color: var(--an-slate-600);
}

.bld-email-editor {
    border: 1px solid var(--an-slate-200);
    border-radius: 7px;
    background: #fff;
    min-height: 140px;
}

/* Quill's Snow theme ships its own toolbar/border chrome — flatten it into our rounded container
   instead of nesting two visually competing borders. */
.bld-email-editor .ql-toolbar.ql-snow {
    border: none;
    border-bottom: 1px solid var(--an-slate-200);
    border-radius: 7px 7px 0 0;
}
.bld-email-editor .ql-container.ql-snow {
    border: none;
    border-radius: 0 0 7px 7px;
    font-size: 13.5px;
}

.bld-email-preview {
    border: 1px solid var(--an-slate-200);
    border-radius: 7px;
    padding: 12px;
    background: var(--an-slate-50);
    max-height: 320px;
    overflow-y: auto;
}

.bld-option-row {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
    align-items: center;
}

.bld-prop-advanced summary {
    cursor: pointer;
    color: var(--an-slate-500);
    font-size: 12.5px;
    margin: 10px 0;
}

.bld-loading { padding: 60px; text-align: center; color: var(--an-slate-500); }

/* design-mode field wrapper interaction guard */
.af-design { pointer-events: none; }

/* ---------- live theme preview (canvas) ---------- */
/* The wrapper carries the FormTheme custom props so af- fields preview the real theme.
   .af-form already paints var(--af-bg); the page cards pick up var(--af-page). */
.bld-canvas-theme {
    background: transparent;
    min-height: 100%;
    padding: 8px;
    border-radius: 12px;
}

.bld-canvas-theme .bld-page { background: var(--af-page); }

/* ---------- theme panel ---------- */
.bld-theme-hint {
    font-size: 12px;
    color: var(--an-slate-400);
    margin: 0 0 16px;
    line-height: 1.5;
}

.bld-logo-preview {
    margin: -4px 0 16px;
    padding: 12px;
    border: 1px solid var(--an-slate-200);
    border-radius: 9px;
    background: var(--an-slate-50);
    text-align: center;
}

.bld-logo-preview-img {
    max-width: 100%;
    max-height: 56px;
    object-fit: contain;
}

.bld-logo-preview-name {
    margin: 6px 0 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--an-slate-600);
}

.bld-logo-preview-caption {
    margin: 6px 0 0;
    font-size: 11.5px;
    color: var(--an-slate-400);
    line-height: 1.5;
}

.bld-logo-preview-empty { margin: 0; }

.bld-color-row { display: flex; gap: 8px; align-items: center; }

.bld-color-swatch {
    width: 40px;
    height: 34px;
    padding: 2px;
    border: 1px solid var(--an-slate-200);
    border-radius: 7px;
    background: #fff;
    cursor: pointer;
    flex: none;
}

.bld-color-hex { flex: 1; }

/* ---------- logic panel ---------- */
.bld-logic-open {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    margin-bottom: 16px;
    border: 1px solid var(--an-slate-200);
    border-radius: 9px;
    background: #fff;
    cursor: pointer;
    text-align: left;
}

.bld-logic-open:hover { border-color: var(--an-primary); }

.bld-logic-open-text { display: flex; flex-direction: column; gap: 2px; }

.bld-logic-open-text strong { font-size: 13.5px; color: var(--an-ink); }

.bld-logic-open-text small { font-size: 11.5px; color: var(--an-slate-500); }

.bld-logic-open-count {
    min-width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--an-slate-100);
    color: var(--an-slate-600);
    font-size: 12px;
    font-weight: 600;
}

.bld-logic-back {
    background: none;
    border: none;
    color: var(--an-primary);
    font-size: 13px;
    cursor: pointer;
    padding: 0 0 12px;
}

/* Rules read as typeset sentences: a thin "reasoning rail" runs down each rule with SI/ENTONCES
   node markers on it, field names render as slate chips, respondent values as teal-washed chips,
   and connective words stay quiet text. The rail is structural, not decorative — rules evaluate
   top to bottom (SI flows into ENTONCES; later rules override earlier ones), and the card
   ordinal exists for the same reason. */

.bld-logic-card {
    position: relative;
    border: 1px solid var(--an-slate-200);
    border-radius: 10px;
    padding: 12px 12px 8px;
    margin-bottom: 10px;
    background: #fff;
    box-shadow: var(--an-shadow-sm);
    transition: box-shadow .15s ease;
}

.bld-logic-card:hover { box-shadow: var(--an-shadow-md); }

.bld-logic-ordinal {
    position: absolute;
    top: 10px;
    right: 12px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--an-slate-400);
    cursor: default;
}

/* ---- the reasoning rail ---- */
.bld-logic-flow, .bld-logic-ghost { position: relative; }

.bld-logic-flow::before, .bld-logic-ghost::before {
    content: "";
    position: absolute;
    left: 2.5px;
    top: 10px;
    bottom: 10px;
    width: 2px;
    border-radius: 1px;
    background: linear-gradient(to bottom, var(--an-slate-300), var(--an-primary));
}

.bld-logic-node { position: relative; padding-left: 16px; }

.bld-logic-node + .bld-logic-node { margin-top: 8px; }

.bld-logic-node::before {
    content: "";
    position: absolute;
    left: 0;
    top: 6px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--an-ink);
}

.bld-logic-node-then::before { background: var(--an-primary); }

.bld-logic-marker {
    display: block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .1em;
    color: var(--an-ink);
    margin-bottom: 3px;
}

.bld-logic-marker-then { color: var(--an-primary-dark); }

/* ---- clause typography ---- */
.bld-logic-clause {
    display: block;
    font-size: 12.5px;
    line-height: 1.9;
    color: var(--an-slate-600);
}

.bld-chip {
    display: inline;
    padding: 2px 6px;
    border-radius: 5px;
    background: var(--an-slate-100);
    color: var(--an-ink);
    font-weight: 600;
    font-size: 12px;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

.bld-chip-value {
    background: var(--an-primary-subtle);
    color: var(--an-primary-dark);
}

.bld-logic-connective { color: var(--an-slate-500); }

.bld-logic-connective-join {
    font-weight: 700;
    font-size: 11px;
    letter-spacing: .06em;
    text-transform: uppercase;
}

/* ---- card footer ---- */
.bld-logic-card-actions {
    display: flex;
    gap: 4px;
    align-items: center;
    margin-top: 10px;
    padding-top: 6px;
    border-top: 1px solid var(--an-slate-100);
}

.bld-logic-card-actions-spacer { flex: 1; }

.bld-logic-edit {
    background: none;
    border: none;
    color: var(--an-primary);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
}

.bld-logic-edit:hover { background: var(--an-primary-subtle); }

/* ---- empty state: a ghost rule teaches the sentence shape ---- */
.bld-logic-empty { padding: 6px 2px 2px; }

.bld-logic-ghost {
    opacity: .55;
    filter: saturate(.4);
    margin-bottom: 12px;
    pointer-events: none;
}

.bld-logic-empty-text {
    font-size: 12.5px;
    color: var(--an-slate-500);
    line-height: 1.55;
    margin: 0 0 12px;
}

/* ---- editor: the rail expands, sections hang off it ---- */
.bld-logic-editor-flow {
    position: relative;
    padding-left: 16px;
}

.bld-logic-editor-flow::before {
    content: "";
    position: absolute;
    left: 2.5px;
    top: 10px;
    bottom: 10px;
    width: 2px;
    border-radius: 1px;
    background: linear-gradient(to bottom, var(--an-slate-300), var(--an-primary));
    transform-origin: top;
    animation: bld-rail-draw .24s ease-out;
}

@keyframes bld-rail-draw {
    from { transform: scaleY(0); }
    to { transform: scaleY(1); }
}

.bld-logic-section { position: relative; animation: bld-node-in .18s ease-out both; }

.bld-logic-section-then { animation-delay: .08s; }

@keyframes bld-node-in {
    from { opacity: 0; transform: translateY(3px); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .bld-logic-editor-flow::before, .bld-logic-section { animation: none; }
    .bld-logic-card { transition: none; }
}

.bld-logic-section::before {
    content: "";
    position: absolute;
    left: -16px;
    top: 5px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--an-ink);
}

.bld-logic-section-then::before { background: var(--an-primary); }

.bld-logic-section-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    min-height: 24px;
}

.bld-logic-section-head .bld-logic-marker { margin-bottom: 0; }

.bld-logic-match {
    border: 1px solid transparent;
    border-radius: 6px;
    background: var(--an-slate-50);
    color: var(--an-slate-600);
    font-size: 11.5px;
    padding: 3px 4px;
    max-width: 100%;
    cursor: pointer;
}

.bld-logic-match:hover { border-color: var(--an-slate-200); background: #fff; }

/* ---- clause groups (one condition / one action) ---- */
.bld-logic-group {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 5px;
    border: 1px solid var(--an-slate-200);
    border-left: 2px solid var(--an-slate-300);
    border-radius: 8px;
    padding: 8px 26px 8px 8px;
    margin-bottom: 6px;
    background: #fff;
}

.bld-logic-section-then .bld-logic-group { border-left-color: var(--an-primary); }

.bld-logic-duo {
    display: flex;
    gap: 5px;
}

.bld-logic-duo > * { flex: 1; min-width: 0; }

.bld-logic-select {
    width: 100%;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 5px 7px;
    font-size: 12.5px;
    background: var(--an-slate-50);
    color: var(--an-ink);
    min-width: 0;
    box-sizing: border-box;
}

select.bld-logic-select { cursor: pointer; }

.bld-logic-select:hover { border-color: var(--an-slate-200); background: #fff; }

.bld-logic-select:focus-visible, .bld-logic-match:focus-visible {
    border-color: var(--an-primary);
    outline: none;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(22, 163, 133, .14);
}

.bld-logic-formula { font-family: Consolas, "Courier New", monospace; font-size: 12px; }

.bld-logic-remove {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 5px;
    background: none;
    color: var(--an-slate-300);
    font-size: 11px;
    cursor: pointer;
}

.bld-logic-remove:hover { color: var(--an-error); background: #FEF2F2; }

.bld-logic-remove:focus-visible { outline: 2px solid var(--an-primary); outline-offset: 1px; }

.bld-logic-add {
    align-self: flex-start;
    background: none;
    border: none;
    color: var(--an-primary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 4px 0;
    margin-bottom: 14px;
}

.bld-logic-add:hover { color: var(--an-primary-dark); text-decoration: underline; }

.bld-logic-add:focus-visible, .bld-logic-edit:focus-visible, .bld-logic-delete:focus-visible {
    outline: 2px solid var(--an-primary);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ---- editor footer ---- */
.bld-logic-editor-footer {
    margin-top: 4px;
    padding-top: 10px;
    border-top: 1px solid var(--an-slate-100);
    display: flex;
    justify-content: flex-end;
}

.bld-logic-delete {
    background: none;
    border: none;
    color: var(--an-error);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 2px;
}

.bld-logic-delete:hover { text-decoration: underline; }

/* ---- list-level add button ---- */
.bld-logic-add-row {
    width: 100%;
    padding: 8px;
    margin: 4px 0 14px;
    border: 1px dashed var(--an-slate-300);
    border-radius: 8px;
    background: none;
    color: var(--an-slate-500);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
}

.bld-logic-add-row:hover { border-color: var(--an-primary); color: var(--an-primary); background: var(--an-primary-subtle); }

.bld-logic-add-row:focus-visible { outline: 2px solid var(--an-primary); outline-offset: 2px; }

.bld-logic-formula-warning { font-size: 11.5px; color: var(--an-error); margin: 0; }

/* ---- calculate action: field-token insert + operator buttons + live preview ---- */
.bld-logic-formula-ops { display: flex; flex-wrap: wrap; gap: 4px; }

.bld-logic-formula-op {
    flex: none;
    min-width: 26px;
    height: 24px;
    padding: 0 6px;
    border: 1px dashed var(--an-slate-300);
    border-radius: 6px;
    background: none;
    color: var(--an-primary);
    font-size: 13px;
    font-weight: 700;
    font-family: Consolas, "Courier New", monospace;
    cursor: pointer;
}

.bld-logic-formula-op:hover { border-color: var(--an-primary); background: var(--an-primary-subtle); }

.bld-logic-formula-op:focus-visible { outline: 2px solid var(--an-primary); outline-offset: 1px; }

.bld-logic-formula-preview {
    font-size: 11.5px;
    color: var(--an-slate-600);
    background: var(--an-slate-50);
    border: 1px solid var(--an-slate-200);
    border-radius: 6px;
    padding: 4px 7px;
    margin: 0;
}

/* ---- rule search ---- */
.bld-logic-search {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--an-slate-200);
    border-radius: 8px;
    padding: 7px 10px;
    margin-bottom: 12px;
    font-size: 12.5px;
    color: var(--an-ink);
    background: #fff;
}

.bld-logic-search::placeholder { color: var(--an-slate-400); }

.bld-logic-search:focus {
    border-color: var(--an-primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(22, 163, 133, .14);
}

/* ---- rule filters (action type / field) ---- */
.bld-logic-filter-row {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.bld-logic-filter {
    flex: 1;
    min-width: 0;
    box-sizing: border-box;
    border: 1px solid var(--an-slate-200);
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 12.5px;
    color: var(--an-ink);
    background: #fff;
    cursor: pointer;
}

.bld-logic-filter:hover { border-color: var(--an-slate-300); }

.bld-logic-filter:focus-visible {
    border-color: var(--an-primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(22, 163, 133, .14);
}

/* ---- disabled rule cards ---- */
.bld-logic-card-off { opacity: .55; }

.bld-logic-off-pill {
    display: inline-flex;
    align-items: center;
    height: 18px;
    padding: 0 8px;
    margin-bottom: 6px;
    border-radius: 999px;
    background: var(--an-slate-100);
    color: var(--an-slate-500);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}

/* ---- action-row target controls: single-target select + quick-add, and the two-select copy row ---- */
.bld-logic-target-row { display: flex; align-items: center; gap: 5px; }

.bld-logic-target-row > .bld-logic-select { flex: 1; min-width: 0; }

.bld-logic-copy-row { display: flex; align-items: center; gap: 6px; }

.bld-logic-copy-row > .bld-logic-select { flex: 1; min-width: 0; }

.bld-logic-quickadd {
    flex: none;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed var(--an-slate-300);
    border-radius: 6px;
    background: none;
    color: var(--an-primary);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    padding: 0;
}

.bld-logic-quickadd:hover { border-color: var(--an-primary); background: var(--an-primary-subtle); }

.bld-logic-quickadd:focus-visible { outline: 2px solid var(--an-primary); outline-offset: 1px; }
