/* ── Root ──────────────────────────────────────────────────────────────────── */

.fb-root {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 13px;
    color: #1c1917;
    padding: 16px;
    background: #fafaf9;
    border: 1px solid #e7e5e4;
    border-radius: 8px;
    display: inline-block;
    min-width: 400px;
}

/* ── Group ───────────────────────────────────────────────────────────────── */

.fb-group {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.fb-group--root {
    gap: 0;
}

.fb-group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    min-height: 34px;
}

/* Tree connector — left bar + horizontal tick for each child */
.fb-group-children {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-left: 10px;
    padding-left: 18px;
    border-left: 2px solid #d6d3d1;
    margin-top: 4px;
    padding-bottom: 4px;
}

.fb-group-children:empty {
    display: none;
}

/* ── Node (atom row) ─────────────────────────────────────────────────────── */

.fb-node {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
    padding: 3px 0;
}

/* ── Pill wrapper ────────────────────────────────────────────────────────── */

.fb-pill-wrapper {
    display: inline-block;
    position: relative;
}

/* ── Overlay (click-outside) ─────────────────────────────────────────────── */

.fb-overlay {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: transparent;
}

/* ── Pills ───────────────────────────────────────────────────────────────── */

.fb-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px 4px 12px;
    border-radius: 4px;
    border: 1px solid transparent;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
    transition: filter 0.12s, box-shadow 0.12s;
    font-family: inherit;
}

.fb-pill:hover {
    filter: brightness(0.93);
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.fb-pill:active {
    filter: brightness(0.87);
}

/* Group op: violet */
.fb-pill--group {
    background: #f5f3ff;
    color: #5b21b6;
    border-color: #c4b5fd;
    font-weight: 600;
    min-width: 60px;
    justify-content: space-between;
}

/* Field: warm amber */
.fb-pill--field {
    background: #fff7ed;
    color: #9a3412;
    border-color: #fdba74;
}

/* Operator: neutral — deliberately understated */
.fb-pill--operator {
    background: #f9fafb;
    color: #374151;
    border-color: #9ca3af;
}

/* Value: teal */
.fb-pill--value {
    background: #f0fdfa;
    color: #0f766e;
    border-color: #5eead4;
}

.fb-chevron {
    width: 11px;
    height: 11px;
    opacity: 0.7;
    flex-shrink: 0;
}

/* ── Dropdown panel ──────────────────────────────────────────────────────── */

.fb-dropdown-panel {
    background: #fff;
    border: 1px solid #e7e5e4;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12), 0 2px 6px rgba(0,0,0,0.06);
    min-width: 150px;
    overflow: hidden;
    padding: 4px 0;
}

.fb-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 7px 14px;
    text-align: left;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    color: #1c1917;
    white-space: nowrap;
    transition: background 0.1s;
}

.fb-dropdown-item:hover {
    background: #f5f5f4;
}

.fb-dropdown-item--selected {
    background: #f5f3ff;
    color: #5b21b6;
    font-weight: 600;
}

.fb-dropdown-item--selected:hover {
    background: #ede9fe;
}

/* ── Menu icons (inside add dropdown) ───────────────────────────────────── */

.fb-menu-icon {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.fb-menu-icon--condition {
    color: #9a3412;
}

.fb-menu-icon--group {
    color: #5b21b6;
}

/* ── Value input ─────────────────────────────────────────────────────────── */

.fb-value-wrapper {
    display: inline-flex;
}

.fb-value-input {
    height: 28px;
    padding: 3px 10px;
    border: 1px solid #5eead4;
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    background: #f0fdfa;
    color: #0f766e;
    font-weight: 500;
    min-width: 90px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.fb-value-input::placeholder {
    color: #99f6e4;
    font-weight: 400;
}

.fb-value-input:focus {
    border-color: #2dd4bf;
    box-shadow: 0 0 0 3px rgba(45,212,191,0.15);
    background: #fff;
}

/* Number input — remove arrows in webkit */
.fb-value-input[type="number"]::-webkit-inner-spin-button,
.fb-value-input[type="number"]::-webkit-outer-spin-button {
    opacity: 0.4;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.fb-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1px solid transparent;
    background: none;
    cursor: pointer;
    border-radius: 4px;
    font-size: 12px;
    font-family: inherit;
    padding: 4px 9px;
    line-height: 1;
    transition: background 0.1s, border-color 0.1s, color 0.1s;
}

.fb-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.fb-btn--add {
    background: #fafaf9;
    color: #57534e;
    border-color: #d6d3d1;
    font-weight: 500;
}

.fb-btn--add:hover {
    background: #f5f5f4;
    border-color: #a8a29e;
    color: #1c1917;
}

.fb-btn--add svg {
    width: 13px;
    height: 13px;
    color: #78716c;
}

.fb-btn--delete {
    color: #a8a29e;
    padding: 4px 6px;
    border-radius: 4px;
}

.fb-btn--delete:hover {
    background: #fee2e2;
    color: #dc2626;
    border-color: #fecaca;
}

/* ── Empty group nudge ───────────────────────────────────────────────────── */

.fb-group-children:has(> :first-child) {
    /* has children — keep the border */
}

/* ── Drag-and-drop ───────────────────────────────────────────────────────── */

/* Drag handle icon shown at the start of each draggable row */
.fb-drag-handle {
    display: inline-flex;
    align-items: center;
    cursor: grab;
    color: #a8a29e;
    padding: 0 3px;
    user-select: none;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity 0.1s;
    font-size: 13px;
    line-height: 1;
}

.fb-node:hover .fb-drag-handle,
.fb-group-header:hover .fb-drag-handle {
    opacity: 1;
}

.fb-drag-handle:hover {
    color: #57534e;
}

/* Row being dragged — fade it out so you can see the ghost */
.fb-row--dragging {
    opacity: 0.35;
}

/* Top-half hover: violet border above */
.fb-drop-above {
    box-shadow: 0 -2px 0 0 #7c3aed;
}

/* Bottom-half hover: violet border below */
.fb-drop-below {
    box-shadow: 0 2px 0 0 #7c3aed;
}

/* Fixed indicator line that tracks the pointer during drag */
.fb-drop-indicator {
    position: fixed;
    height: 2px;
    background: #7c3aed;
    border-radius: 1px;
    pointer-events: none;
    z-index: 10000;
    display: none;
}

.fb-drop-indicator::before {
    content: '';
    position: absolute;
    left: -4px;
    top: -3px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #7c3aed;
}

/* ── Label pill ──────────────────────────────────────────────────────────── */

/* Amber/gold — distinct from field (warm amber) and group (violet) */
.fb-pill--label {
    background: #fefce8;
    color: #854d0e;
    border-color: #fde047;
    font-weight: 600;
    max-width: 320px;
    justify-content: space-between;
}

/* ── Label input (inline edit for node names) ────────────────────────────── */

.fb-label-input {
    height: 28px;
    padding: 3px 10px;
    border: 1px solid #fde047;
    border-radius: 4px;
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    outline: none;
    background: #fefce8;
    color: #854d0e;
    min-width: 160px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.fb-label-input::placeholder {
    color: #ca8a04;
    font-weight: 400;
}

.fb-label-input:focus {
    border-color: #eab308;
    box-shadow: 0 0 0 3px rgba(234,179,8,0.18);
    background: #fff;
}

/* ── Label action buttons ────────────────────────────────────────────────── */

/* Tag/pencil icon button — shown on hover in unlabelled nodes */
.fb-btn--label {
    color: #a8a29e;
    padding: 4px 6px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.1s, background 0.1s, color 0.1s;
}

.fb-node:hover .fb-btn--label,
.fb-group-header:hover .fb-btn--label {
    opacity: 1;
}

.fb-btn--label:hover {
    background: #fef9c3;
    color: #854d0e;
}

/* When label-set button is shown on unlabelled atoms keep it always visible on hover */
.fb-btn--label-set {
    opacity: 0;
}

.fb-node:hover .fb-btn--label-set {
    opacity: 1;
}

/* Commit (✓) button */
.fb-btn--label-commit {
    color: #15803d;
    padding: 4px 6px;
    border-radius: 4px;
}

.fb-btn--label-commit:hover {
    background: #dcfce7;
    color: #166534;
}

/* Cancel (✗) button */
.fb-btn--label-cancel {
    color: #a8a29e;
    padding: 4px 6px;
    border-radius: 4px;
}

.fb-btn--label-cancel:hover {
    background: #fee2e2;
    color: #dc2626;
}

/* ── Inner header (group op + add, shown below label pill when expanded) ─── */

.fb-group-inner-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0 4px 10px;
    min-height: 34px;
    border-left: 2px solid #fde047;
    margin-left: 10px;
    margin-top: 2px;
}

/* ── Atom content row (detail shown when labelled atom is expanded) ────────── */

/* flex-basis:100% pushes this onto its own line within the wrapping fb-node flex */
.fb-atom-content {
    flex-basis: 100%;
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
    padding: 3px 0 3px 10px;
    border-left: 2px solid #fde047;
    margin-left: 10px;
}

/* ── Set-label menu item ─────────────────────────────────────────────────── */

.fb-menu-icon--label {
    color: #854d0e;
}

.fb-dropdown-item--label {
    border-top: 1px solid #f5f5f4;
    margin-top: 2px;
    padding-top: 8px;
}
