/* =========================================
   CENTER PANE: BUILDER (INPUT + CANVAS)
   ========================================= */

.builder-card {
    background: #fff;
    border: none;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
}

/* Center Input Header */
.center-input-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-light);
    background: #fff;
    /* Sticky Top if needed, but flex handles it */
}

.query-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}

.query-input-shell {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1;
}

.query-input {
    width: 100%;
    padding: 14px 18px;
    border: 1px solid var(--border-light);
    border-radius: 10px;
    font-size: 1.05rem;
    transition: all 0.2s;
    outline: none;
    padding-right: 54px;
    background: #ffffff;
    /* Pure White */
    color: var(--text-primary);
    font-family: inherit;
}

.query-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(30, 120, 255, 0.15);
    background: #fff;
}

.query-input::placeholder {
    color: #BBB;
}

.send-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-primary);
    color: white;
    border-radius: 8px;
    transition: background 0.2s;
}

.send-btn:hover {
    background: var(--accent-strong);
}

.send-btn.loading svg {
    animation: shake 0.4s ease-in-out infinite;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px) rotate(-8deg); }
    75% { transform: translateX(3px) rotate(8deg); }
}

/* ── Query input glow pulse while processing ──────────────── */

.query-input-shell.loading .query-input {
    border-color: var(--accent-primary);
    animation: input-glow 2s ease-in-out infinite;
}

@keyframes input-glow {
    0%, 100% { box-shadow: 0 0 0 3px rgba(30, 120, 255, 0.10); }
    50%      { box-shadow: 0 0 0 5px rgba(30, 120, 255, 0.25); }
}

/* ── Loading text dot animation ───────────────────────────── */

.loading-dots::after {
    content: '';
    animation: dots 1.4s steps(4, end) infinite;
}

@keyframes dots {
    0%  { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}


/* Builder Header (Tools) */
.builder-header {
    height: 56px;
    min-height: 56px;
    flex: 0 0 auto;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #ffffff;
    /* Unified White */
}

.builder-header.hidden {
    display: none !important;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--border-light);
}

.status-dot.active {
    background: var(--warning);
    box-shadow: 0 0 0 2px #FEF3C7;
}

.status-dot.ready {
    background: var(--success);
    box-shadow: 0 0 0 2px #D1FAE5;
}

/* The Logic Canvas */
.logic-canvas {
    padding: 16px 24px;
    background: #FAFAFA;
    border-bottom: 1px solid var(--border-light);
    display: none;
    /* Default Hidden */
    align-items: center;
    flex-wrap: nowrap;
    gap: 10px;
    transition: background 0.3s;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.logic-canvas::-webkit-scrollbar {
    display: none;
}

.logic-canvas.active {
    display: flex;
    /* Show when active */
    background: #fff;
}

.logic-canvas.hidden {
    display: none !important;
}

/* Components: Logic Block */
.logic-block {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: white;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    font-weight: 600;
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
    cursor: default;
    user-select: none;
    transition: all 0.2s;
    flex-shrink: 0;
    white-space: nowrap;
}

.logic-label {
    line-height: 1.3;
}

.logic-delete-btn {
    width: 30px;
    height: 30px;
    min-width: 30px;
    min-height: 30px;
    border: 1px solid var(--border-light);
    border-radius: 999px;
    background: #fff;
    color: var(--text-tertiary);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    margin-left: 2px;
    transition: all 0.15s ease;
}

.logic-delete-btn:hover {
    color: #b42318;
    border-color: #f5c2c0;
    background: #fff3f2;
}

.logic-delete-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.16);
}

.logic-add-btn {
    height: 38px;
    min-width: 124px;
    padding: 0 16px;
    border: 1px solid #bfdbfe;
    border-radius: 999px;
    background: linear-gradient(180deg, #f8fbff 0%, #ecf4ff 100%);
    color: #1d4ed8;
    font-size: 0.83rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
    transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.logic-add-btn::before {
    content: '+';
    width: 20px;
    height: 20px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 800;
    color: inherit;
    background: #dbeafe;
}

.logic-add-btn:hover {
    border-color: #93c5fd;
    background: linear-gradient(180deg, #eef5ff 0%, #e1eeff 100%);
    color: #1e40af;
    transform: translateY(-1px);
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.16);
}

.logic-add-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 3px rgba(37, 99, 235, 0.15);
}

.logic-add-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.logic-empty-add-btn {
    margin-top: 14px;
    min-width: 136px;
    background: #2563eb;
    border-color: #1d4ed8;
    color: #ffffff;
    box-shadow: 0 6px 14px rgba(37, 99, 235, 0.22);
}

.logic-empty-add-btn::before {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

.logic-empty-add-btn:hover {
    background: #1d4ed8;
    border-color: #1e40af;
    color: #ffffff;
    box-shadow: 0 8px 16px rgba(30, 64, 175, 0.28);
}

.logic-block:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    border-color: var(--text-tertiary);
}

.logic-block.selected {
    border-color: var(--accent-primary);
    background: var(--accent-light);
    color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.logic-op {
    font-size: 0.75rem;
    font-weight: 800;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 4px;
    transition: all 0.2s ease;
    user-select: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.logic-op.is-or {
    background: #ffffff;
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 4px 12px;
}

.logic-op:hover {
    background: var(--accent-primary) !important;
    color: #ffffff !important;
    transform: scale(1.05);
}

.logic-op::after {
    content: '⇆';
    font-size: 0.8rem;
    opacity: 0.5;
}

.logic-group-box {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    border: 1px solid var(--border-light);
    background: #fafbfc;
    border-radius: 10px;
    flex-shrink: 0;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.logic-group-box::-webkit-scrollbar {
    display: none;
}

.logic-group-single {
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.logic-add-row {
    width: 100%;
    display: flex;
    justify-content: flex-start;
    margin-top: 6px;
}

/* side-add-anchor: no longer needed, add button moved to toolbar */

@media (max-width: 600px) {
    .logic-delete-btn {
        width: 34px;
        height: 34px;
        min-width: 34px;
        min-height: 34px;
    }

    .logic-add-btn {
        min-width: 112px;
        height: 36px;
        padding: 0 12px;
        font-size: 0.8rem;
    }

    .logic-add-btn::before {
        width: 18px;
        height: 18px;
        font-size: 0.82rem;
    }

    .logic-add-row {
        justify-content: flex-start;
    }

}

/* Builder Toolbar */
.builder-tools {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
}

.builder-tools.hidden {
    display: none;
}

.builder-context {
    display: flex;
    align-items: center;
    min-width: 0;
}

.builder-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.tool-btn {
    height: 32px;
    padding: 0 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.tool-btn:hover {
    background: var(--bg);
    color: var(--text-primary);
}

.tool-btn.primary {
    background: var(--accent-primary);
    color: white;
    border: none;
}

.tool-btn.primary:hover {
    background: var(--accent-strong);
}

/* Tool Select Styles */
.tool-select-wrapper {
    height: 32px;
    padding: 0 8px;
    display: flex;
    align-items: center;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    background: #fff;
    transition: all 0.2s;
}

.tool-select-wrapper:hover {
    border-color: var(--accent-primary);
}

.tool-context-label {
    font-size: 0.78rem;
    font-weight: 700;
    margin-right: 8px;
    color: var(--text-secondary);
    white-space: nowrap;
}

@media (max-width: 600px) {
    .builder-tools {
        gap: 8px;
    }

    .builder-actions .tool-btn {
        min-width: 96px;
    }

    .tool-context-label {
        margin-right: 6px;
        font-size: 0.74rem;
    }
}

.tool-select {
    border: none;
    background: transparent;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    outline: none;
    cursor: pointer;
    padding-right: 4px;
}

.tool-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tool-btn.loading,
.send-btn.loading {
    opacity: 0.7;
    cursor: wait !important;
    pointer-events: none;
}
